跳至內容
選單
此問題已被標幟
2 回覆
7025 瀏覽次數

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!

頭像
捨棄
最佳答案

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.
頭像
捨棄
最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
11月 23
2604
1
8月 23
2310
0
2月 23
1502
0
9月 22
1390
0
9月 21
2605