From 3a7db03295a9af069c5b5fa6f8030c9e72a2c689 Mon Sep 17 00:00:00 2001 From: nie Date: Mon, 1 Mar 2021 15:25:01 +0000 Subject: [PATCH] [FIX] payment: link transaction to invoice with payment link Steps: - Install account,payment - Go to Invoicing - Create an invoice - Click Actions > Generate a Payment Link - Follow the generated link - Pay Bug: The transaction is not linked to the sale order in the link table `account_invoice_transaction_rel` Explanation: This fix is broadly mimicking the behavior of the sales module regarding the link of an order to a transaction, adding `invoice_id`s where they are needed throughout the payment process in order to link the transaction to the invoice. opw:2451534 closes odoo/odoo#67296 X-original-commit: 7c6d06fa5858f79f3b22cdeaf74cdc26a642742f Signed-off-by: Nicolas Lempereur (nle) Signed-off-by: backspac --- addons/payment/controllers/portal.py | 11 +++++++++++ addons/payment/static/src/js/payment_form.js | 1 + addons/payment/views/payment_templates.xml | 2 ++ addons/payment/wizards/payment_link_wizard.py | 2 ++ 4 files changed, 16 insertions(+) diff --git a/addons/payment/controllers/portal.py b/addons/payment/controllers/portal.py index eb102932de0..5fcc0147ab7 100644 --- a/addons/payment/controllers/portal.py +++ b/addons/payment/controllers/portal.py @@ -158,6 +158,8 @@ class WebsitePayment(http.Controller): if not token_ok: raise werkzeug.exceptions.NotFound + invoice_id = kw.get('invoice_id') + # Default values values = { 'amount': 0.0, @@ -183,6 +185,12 @@ class WebsitePayment(http.Controller): except: order_id = None + if invoice_id: + try: + values['invoice_id'] = int(invoice_id) + except ValueError: + invoice_id = None + # Check currency if currency_id: try: @@ -266,6 +274,7 @@ class WebsitePayment(http.Controller): def transaction(self, acquirer_id, reference, amount, currency_id, partner_id=False, **kwargs): acquirer = request.env['payment.acquirer'].browse(acquirer_id) order_id = kwargs.get('order_id') + invoice_id = kwargs.get('invoice_id') reference_values = order_id and {'sale_order_ids': [(4, order_id)]} or {} reference = request.env['payment.transaction']._compute_reference(values=reference_values, prefix=reference) @@ -281,6 +290,8 @@ class WebsitePayment(http.Controller): if order_id: values['sale_order_ids'] = [(6, 0, [order_id])] + elif invoice_id: + values['invoice_ids'] = [(6, 0, [invoice_id])] reference_values = order_id and {'sale_order_ids': [(4, order_id)]} or {} reference_values.update(acquirer_id=int(acquirer_id)) diff --git a/addons/payment/static/src/js/payment_form.js b/addons/payment/static/src/js/payment_form.js index 59ae4b0e826..47e795d209d 100644 --- a/addons/payment/static/src/js/payment_form.js +++ b/addons/payment/static/src/js/payment_form.js @@ -284,6 +284,7 @@ publicWidget.registry.PaymentForm = publicWidget.Widget.extend({ 'error_url': self.options.errorUrl, 'callback_method': self.options.callbackMethod, 'order_id': self.options.orderId, + 'invoice_id': self.options.invoiceId, }, }).then(function (result) { if (result) { diff --git a/addons/payment/views/payment_templates.xml b/addons/payment/views/payment_templates.xml index f1047c0f847..b8de80be83e 100644 --- a/addons/payment/views/payment_templates.xml +++ b/addons/payment/views/payment_templates.xml @@ -30,10 +30,12 @@ t-att-data-partner-id="partner_id" t-att-data-callback-method="callback_method or ''" t-att-data-order-id="order_id or ''" + t-att-data-invoice-id="invoice_id or ''" t-att-data-mode="mode"> + diff --git a/addons/payment/wizards/payment_link_wizard.py b/addons/payment/wizards/payment_link_wizard.py index 53ca40e8762..ccd69ed342e 100644 --- a/addons/payment/wizards/payment_link_wizard.py +++ b/addons/payment/wizards/payment_link_wizard.py @@ -80,6 +80,8 @@ class PaymentLinkWizard(models.TransientModel): ) if payment_link.company_id: link += '&company_id=%s' % payment_link.company_id.id + if payment_link.res_model == 'account.move': + link += '&invoice_id=%s' % payment_link.res_id payment_link.link = link @api.model