From 5c12ec09c536e60bf354670672104e1067785466 Mon Sep 17 00:00:00 2001
From: "Thomas Lefebvre (thle)" <thle@odoo.com>
Date: Tue, 23 May 2023 13:36:00 +0000
Subject: [PATCH] [FIX] website_sale: authorise the change of shipping address

Steps to reproduce:
Without being logged in,
complete the purchase flow on the ecommerce,
taking care to have a different billing
and shipping address.
If you change the delivery address,
you will get an access error.

Cause:
In some cases, we do not have access to
the `name` field of the `partner` record.

Solution:
Add `sudo` to be able to read the fields.

opw-3276877

closes odoo/odoo#122258

X-original-commit: 1d6ae6bbc765de5673fab5830a81510a1d8857ae
Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
Signed-off-by: Lefebvre Thomas (thle) <thle@odoo.com>
---
 addons/website_sale/controllers/main.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py
index e76c43fee993..2ea9e90dbebf 100644
--- a/addons/website_sale/controllers/main.py
+++ b/addons/website_sale/controllers/main.py
@@ -712,7 +712,7 @@ class WebsiteSale(http.Controller):
         # prevent name change if invoices exist
         if data.get('partner_id'):
             partner = request.env['res.partner'].browse(int(data['partner_id']))
-            if partner.exists() and partner.name and not partner.sudo().can_edit_vat() and 'name' in data and (data['name'] or False) != (partner.name or False):
+            if partner.exists() and partner.sudo().name and not partner.sudo().can_edit_vat() and 'name' in data and (data['name'] or False) != (partner.sudo().name or False):
                 error['name'] = 'error'
                 error_message.append(_('Changing your name is not allowed once invoices have been issued for your account. Please contact us directly for this operation.'))
 
-- 
GitLab