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.")