Skip to Content
Menu
This question has been flagged
2 Replies
7002 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
Related Posts Replies Views Activity
1
Nov 23
2587
1
Aug 23
2292
0
Feb 23
1472
0
Sep 22
1378
0
Sep 21
2580