From 43e1d21e0e0e527953ec7f9e7f0cf819faeb4fda Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Mon, 21 Jun 2021 14:35:29 +0000 Subject: [PATCH] [FIX] base: fix the VAT verification Steps to reproduce the bug: - Go to settings > create a new company : - Choose the country : `Mexico` - fill in the VAT field : ESA2005273X1 - save - Validation error is triggered Problem: The Mexican VAT can be on the format: "MXESA2005273X1" or "ESA2005273X1". But only the "MX .." format is accepted for the moment, and it fails in the case of "ES.." because the function checks if it is a valid Espganol VAT number. In the case of failure, we use the `partner.commercial_partner_id.country_id` to get the country code. The problem is when creating the res.company, we also create a res.partner with a few fields within `VAT` except `country_id` field while we use it in the `check_vat` function : https://github.com/odoo/odoo/blob/7a7aacedde81998ec0f1a7f3283337236e56de42/addons/base_vat/models/res_partner.py#L167 Opw-2573557 closes odoo/odoo#72633 X-original-commit: a6a46c95e4947997892b21f407132574da1c7ff1 Signed-off-by: Nicolas Lempereur (nle) Signed-off-by: Djamel Touati --- addons/sales_team/tests/common.py | 2 +- addons/sales_team/tests/test_sales_team.py | 2 +- odoo/addons/base/models/res_company.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/sales_team/tests/common.py b/addons/sales_team/tests/common.py index be57aebe14e..32709b1ddc4 100644 --- a/addons/sales_team/tests/common.py +++ b/addons/sales_team/tests/common.py @@ -84,7 +84,7 @@ class TestSalesMC(TestSalesCommon): cls.company_2 = cls.env['res.company'].create({ 'name': 'New Test Company', 'email': 'company.2@test.example.com', - 'country_id': cls.env.ref('base.fr'), + 'country_id': cls.env.ref('base.fr').id, }) cls.team_c2 = cls.env['crm.team'].create({ 'name': 'C2 Team1', diff --git a/addons/sales_team/tests/test_sales_team.py b/addons/sales_team/tests/test_sales_team.py index 0ff999789c8..77b7c31b5d2 100644 --- a/addons/sales_team/tests/test_sales_team.py +++ b/addons/sales_team/tests/test_sales_team.py @@ -16,7 +16,7 @@ class TestDefaultTeam(TestSalesCommon): cls.company_2 = cls.env['res.company'].create({ 'name': 'New Test Company', 'email': 'company.2@test.example.com', - 'country_id': cls.env.ref('base.fr'), + 'country_id': cls.env.ref('base.fr').id, }) cls.team_c2 = cls.env['crm.team'].create({ 'name': 'C2 Team1', diff --git a/odoo/addons/base/models/res_company.py b/odoo/addons/base/models/res_company.py index 2f2a8e93128..3ab5758ce0c 100644 --- a/odoo/addons/base/models/res_company.py +++ b/odoo/addons/base/models/res_company.py @@ -210,6 +210,7 @@ class Company(models.Model): 'phone': vals.get('phone'), 'website': vals.get('website'), 'vat': vals.get('vat'), + 'country_id': vals.get('country_id'), }) # compute stored fields, for example address dependent fields partner.flush()