From 97b01d48ba6cf1467e34feaa27e8221d6535bfcc Mon Sep 17 00:00:00 2001
From: Horacio Tellez <hote@odoo.com>
Date: Wed, 12 Apr 2023 14:47:27 +0000
Subject: [PATCH] [FIX] payment: ignoring billing address when exists

Before this fix the payment engine was ignoring the billing address
for sale orders in when processing payments.
After this fix the billing address will be used in the payment details.

opw - 3212748

closes odoo/odoo#118358

Signed-off-by: Horacio Tellez Perez (hote) <hote@odoo.com>
---
 addons/payment/controllers/portal.py | 9 +++++++--
 addons/sale/models/sale.py           | 4 ++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/addons/payment/controllers/portal.py b/addons/payment/controllers/portal.py
index a01403901059..43fee83a61de 100644
--- a/addons/payment/controllers/portal.py
+++ b/addons/payment/controllers/portal.py
@@ -292,8 +292,13 @@ class WebsitePayment(http.Controller):
             'type': 'form_save' if acquirer.save_token != 'none' and partner_id else 'form',
         }
 
+        render_values = {}
         if order_id:
             values['sale_order_ids'] = [(6, 0, [order_id])]
+            order = request.env['sale.order'].sudo().browse(order_id)
+            render_values.update({
+                'billing_partner_id': order.partner_invoice_id.id,
+            })
         elif invoice_id:
             values['invoice_ids'] = [(6, 0, [invoice_id])]
 
@@ -308,10 +313,10 @@ class WebsitePayment(http.Controller):
 
         PaymentProcessing.add_payment_transaction(tx)
 
-        render_values = {
+        render_values.update({
             'partner_id': partner_id,
             'type': tx.type,
-        }
+        })
 
         return acquirer.sudo().render(tx.reference, float(amount), int(currency_id), values=render_values)
 
diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py
index e2c5d3b8a9d7..67f127a56cbd 100644
--- a/addons/sale/models/sale.py
+++ b/addons/sale/models/sale.py
@@ -1042,8 +1042,8 @@ Reason(s) of this behavior could be:
             raise ValidationError(_('A transaction can\'t be linked to sales orders having different currencies.'))
 
         # Ensure the partner are the same.
-        partner = self[0].partner_id
-        if any(so.partner_id != partner for so in self):
+        partner = self[0].partner_invoice_id
+        if any(so.partner_invoice_id != partner for so in self):
             raise ValidationError(_('A transaction can\'t be linked to sales orders having different partners.'))
 
         # Try to retrieve the acquirer. However, fallback to the token's acquirer.
-- 
GitLab