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()