Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
7017 Vistas

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
Descartar
Mejor respuesta

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
Descartar
Mejor respuesta

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

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
nov 23
2601
1
ago 23
2304
0
feb 23
1502
0
sept 22
1388
0
sept 21
2594