From 39d16f085f04059d7fef7e615fa0a94ad1bd62cb Mon Sep 17 00:00:00 2001 From: Ivan Yelizariev Date: Mon, 8 Aug 2022 09:22:47 +0000 Subject: [PATCH] [FIX] website_sale: prevent changing name when invoiced are issued /my/account controller blocks name/vat/company_name updating if there are issued invoices. However Before this commit, user can change name via /shop/address page STEPS 1/ install sales, eCommerce,inventory,Accounting 2/ create a sales order from the portal page, validate and create an invoice from SO and post it 3/ Try to change the name from the Portal > Account Result - not possible = correct 4/ Place a new SO by the same portal user and edit the name on the address before proceeding to checkout [1]: https://github.com/odoo/odoo/blob/1f49528a4b198e8912beb33be921d2855c694e2e/addons/account/controllers/portal.py#L111-L113 opw-2848251 closes odoo/odoo#98335 X-original-commit: 3c8337d17c23779ef265cb5037243b533725c494 Signed-off-by: William Braeckman (wbr) --- addons/website_sale/controllers/main.py | 7 +++++++ addons/website_sale/i18n/website_sale.pot | 8 ++++++++ addons/website_sale/tests/test_sale_process.py | 2 ++ 3 files changed, 17 insertions(+) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 9243ce70829..09c70c1b190 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -918,6 +918,13 @@ class WebsiteSale(http.Controller): error = dict() error_message = [] + # 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 not partner.sudo().can_edit_vat() and 'name' in data and (data['name'] or False) != (partner.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.')) + # Required fields from form required_fields = [f for f in (all_form_values.get('field_required') or '').split(',') if f] diff --git a/addons/website_sale/i18n/website_sale.pot b/addons/website_sale/i18n/website_sale.pot index adc88997ee9..7bce264d2e8 100644 --- a/addons/website_sale/i18n/website_sale.pot +++ b/addons/website_sale/i18n/website_sale.pot @@ -846,6 +846,14 @@ msgid "" "your account. Please contact us directly for this operation." msgstr "" +#. module: website_sale +#: code:addons/website_sale/controllers/main.py:0 +#, python-format +msgid "" +"Changing your name is not allowed once invoices have been issued for your " +"account. Please contact us directly for this operation." +msgstr "" + #. module: website_sale #: model:ir.model.fields,field_description:website_sale.field_product_public_category__child_id msgid "Children Categories" diff --git a/addons/website_sale/tests/test_sale_process.py b/addons/website_sale/tests/test_sale_process.py index 17ba040ad3a..3f1e6ea20f6 100644 --- a/addons/website_sale/tests/test_sale_process.py +++ b/addons/website_sale/tests/test_sale_process.py @@ -206,6 +206,8 @@ class TestWebsiteSaleCheckoutAddress(TransactionCaseWithUserDemo): # 2. Logged in user, edit billing self.default_address_values['partner_id'] = self.demo_partner.id + # Name cannot be changed if there are issued invoices + self.default_address_values['name'] = self.demo_partner.name self.WebsiteSaleController.address(**self.default_address_values) self.assertEqual(self.demo_partner.company_id, self.company_c, "Logged in user edited billing (the partner itself) should not get its company modified.")