This question has been flagged
2 Replies
4769 Views

Hello, I have this function where i create a payment:

def action_order_paid(self):
self.write({'paid': True})
for record in self:
delivery_payment = self.env['account.payment'].create({
'amount': self.delivery_total,
'date': fields.Date.context_today(self),
'currency_id': self.currency_id.id,
'payment_type': 'inbound',
'partner_type': 'customer',
'journal_id': 6,
'partner_id':self.partner_id.id,
})
delivery_payment.action_post()

i want to link this payment with an invoice, can anyone help me with that?

Thanks!

Avatar
Discard
Best Answer

You can use the functionality of register payment on account.move which takes active_ids in account.

account.move

def action_invoice_register_payment(self):
return self.env['account.payment']\
.with_context(active_ids=self.ids, active_model='account.move', active_id=self.id)\
.action_register_payment()
account.payment


def action_register_payment(self):
active_ids = self.env.context.get('active_ids')
if not active_ids:
return ''

return {
'name': _('Register Payment'),
'res_model': len(active_ids) == 1 and 'account.payment' or 'account.payment.register',
'view_mode': 'form',
'view_id': len(active_ids) != 1 and self.env.ref('account.view_account_payment_form_multi').id or self.env.ref('account.view_account_payment_invoice_form').id,
'context': self.env.context,
'target': 'new',
'type': 'ir.actions.act_window',
}
I hope this gives you an idea.
Avatar
Discard
Best Answer

If you make it work, could please share your code ?

Avatar
Discard