[FIX] account_payment: fix failed payment transaction from invoice
Steps to reproduce: - Configure a payment provider (e.g. Stripe) - Go to the portal account of an user (e.g. Marc Demo) - Click on "Manage payment methods" - Save a payment method to create a payment token - /!\ Go back to payment provider configuration and make a typo in the credentials (This will be needed later to trigger a payment transaction error) - Go to Accounting and create an invoice for Marc Demo - Confirm the invoice - Register payment: * Payment Method: Stripe * Saved payment token: [payment token of Marc Demo] - Create payment [1st issue] The payment transaction fails (as the credentials are incorrect), but no information about it appears on the invoice. [2nd issue] It is not possible to register another payment (with the payment provider) because there is an unique constraint on the reference field of "payment.transaction" model and each attempt of registering a payment uses the same reference. Solution: [1st issue] Link invoice to payment transaction. Messages related to payment transaction will be logged on the invoice automatically. [2nd issue] Generate reference with "_compute_reference" method instead of always using the same one. opw-3499200 closes odoo/odoo#140533 X-original-commit: 8c98efe036972c43a95c28509e91c356ddc84084 Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com> Signed-off-by: Anh Thao Pham (pta) <pta@odoo.com>
This commit is contained in:
@@ -197,13 +197,18 @@ class AccountPayment(models.Model):
|
||||
return {
|
||||
'provider_id': self.payment_token_id.provider_id.id,
|
||||
'payment_method_id': self.payment_token_id.payment_method_id.id,
|
||||
'reference': self.ref,
|
||||
'reference': self.env['payment.transaction']._compute_reference(
|
||||
self.payment_token_id.provider_id.code, prefix=self.ref
|
||||
),
|
||||
'amount': self.amount,
|
||||
'currency_id': self.currency_id.id,
|
||||
'partner_id': self.partner_id.id,
|
||||
'token_id': self.payment_token_id.id,
|
||||
'operation': 'offline',
|
||||
'payment_id': self.id,
|
||||
**({'invoice_ids': [Command.set(self._context.get('active_ids', []))]}
|
||||
if self._context.get('active_model') == 'account.move'
|
||||
else {}),
|
||||
**extra_create_values,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user