Skip to Content
Menu
This question has been flagged

Hi hope you will be fine 

i am working on custom module in that module i'm getting all my values from account.payment model and also a journal_id of posted payment after when i populated my all value in custom module form in this form i am creating a journal entry again 

while creating a journal entry i am getting this ERROR

you cannot modify a journal entry linked to a posted payment. 

HERE IS MY CODE WHICH I'M USING TO PASS DATA FROM ACCOUNT.PAYMENT  MODEL TO B MODEL

    def go_to_pdc(self):

        if self.pdc_enable == 'pdc':

            if self.partner_type == 'customer':

                self.pdc_created = True

                context = {

                    'default_payment_id': self.id,

                    'default_name': self.partner_id.name + '-' + self.journal_id.name,

                    'default_bank_account_id': self.journal_id.bank_account_id.id,

                    'default_payee_user_id': self.partner_id.id,

                    'default_company_id': self.company_id.id,

                    'default_amount': self.amount,

                    'default_invoice_ids': [(6, 0, rec.multi_invoice_ids.invoice_id.ids) for rec in self],

                    'default_cheque_date': self.pdc_date,

                    'default_account_cheque_type': 'incoming',

                    'default_status1': 'registered',

                }

                return {

                    'name': _('Incoming'),

                    'view_type': 'form',

                    'view_mode': 'form',

                    'res_model': 'account.cheque',

                    'view_id': self.env.ref('bi_account_cheque.account_incoming_cheque_form_view').id,

                    'type': 'ir.actions.act_window',

                    'domain': [('payment_id', '=', self.id)],

                    'context': context

                }

HERE IS MY CODE FOR CREATING AN JOURNAL ENTRY OF B MODEL DATA

    def set_to_transfer(self):

        if self.amount:

            account_move_obj = self.env['account.move']

            move_lines = []

            if self.account_cheque_type == 'incoming':

                vals = {

                    'name': self.payee_user_id.name,

                    'date': self.cheque_receive_date,

                    'journal_id': self.journal_id.id,

                    'company_id': self.company_id.id,

                    'type': 'entry',

                    'state': 'draft',

                    'ref': self.name,

                    'account_cheque_id': self.id

                }

                account_move = account_move_obj.create(vals)


                debit_vals = {

                    'partner_id': self.payee_user_id.id,

                    'account_id': self.journal_id.default_debit_account_id.id,

                    'debit': self.amount,

                    'move_id': account_move.id,

                    'payment_id': self.payment_id.id,

                    'company_id': self.company_id.id,

                }

                move_lines.append((0, 0, debit_vals))


                credit_vals = {

                    'partner_id': self.payee_user_id.id,

                    'account_id': self.journal_id.clearing_account.id,

                    'credit': self.amount,

                    'move_id': account_move.id,

                    'payment_id': self.payment_id.id,

                    'company_id': self.company_id.id,

                }

                move_lines.append((0, 0, credit_vals))

                account_move.write({'line_ids': move_lines})


                account_move.post()

 

Avatar
Discard
Author Best Answer

move_id = fields.Many2one('account.move')

move = { 'name': self.payment_id.name, 'date': self.cheque_receive_date, 'journal_id': self.journal_id.id, 'company_id': self.company_id.id, 'type': 'entry', 'state': 'draft', 'ref': self.sequence + '- ' + self.cheque_number + '- ' + 'Transferred', 'account_cheque_id': self.id, 'line_ids': [(0, 0, { 'name': self.payment_id.move_name, 'partner_id': self.payee_user_id.id, 'account_id': self.journal_id.default_debit_account_id.id, 'debit': self.amount}), (0, 0, { 'name': self.payment_id.move_name, 'partner_id': self.payee_user_id.id, 'account_id': self.journal_id.clearing_account.id, 'credit': self.amount })] } move_id = self.env['account.move'].create(move) move_id.post()
`               return self.write({'move_id': move_id.id})
                 By this code i just get rid of that Error , in this code i'm not creating dictionary of credit value and debit value separately 

Avatar
Discard
Related Posts Replies Views Activity
1
Aug 24
222
0
Jul 24
265
1
Aug 23
1135
1
Sep 21
3837
1
Jun 21
2821