Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
7019 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Nejlepší odpověď

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

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
lis 23
2601
1
srp 23
2308
0
úno 23
1502
0
zář 22
1389
0
zář 21
2594