From 2b36c8abc35082b4cca77ce1e87fcb474c86bdff Mon Sep 17 00:00:00 2001 From: sesn-odoo Date: Tue, 12 Dec 2023 13:27:43 +0100 Subject: [PATCH] [FIX] base_vat: allow tax IDs starting with 'EU' for non EU countries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary ------- Foreign companies that trade with non-enterprises in the EU may have a VATIN starting with "EU" instead of a country code. However, the tax ID validation does not account for that. Steps to reproduce ------------------ * install base_vat and contacts * create a Canadian company with a tax with the format EU00000000 => you should be met with a validation error. opw-3551347 closes odoo/odoo#146049 X-original-commit: 6e11c34c660cecea7e8a0b56f7f8f3baba70b0c9 Signed-off-by: Josse Colpaert Signed-off-by: Séna Serge Nshimiyimana (sesn) --- addons/base_vat/models/res_partner.py | 10 ++++++---- addons/base_vat/tests/test_validate_ruc.py | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/addons/base_vat/models/res_partner.py b/addons/base_vat/models/res_partner.py index 6d9c04c94e1..94d9f49912a 100644 --- a/addons/base_vat/models/res_partner.py +++ b/addons/base_vat/models/res_partner.py @@ -124,10 +124,6 @@ class ResPartner(models.Model): check_func = getattr(self, check_func_name, None) or getattr(stdnum.util.get_cc_module(country_code, 'vat'), 'is_valid', None) if not check_func: # No VAT validation available, default to check that the country code exists - if country_code.upper() == 'EU': - # Foreign companies that trade with non-enterprises in the EU - # may have a VATIN starting with "EU" instead of a country code. - return True country_code = _eu_country_vat_inverse.get(country_code, country_code) return bool(self.env['res.country'].search([('code', '=ilike', country_code)])) return check_func(vat_number) @@ -227,6 +223,12 @@ class ResPartner(models.Model): # First check with country code as prefix of the TIN vat_country_code, vat_number_split = self._split_vat(vat_number) + + if vat_country_code == 'eu' and default_country not in self.env.ref('base.europe').country_ids: + # Foreign companies that trade with non-enterprises in the EU + # may have a VATIN starting with "EU" instead of a country code. + return True + vat_has_legit_country_code = self.env['res.country'].search([('code', '=', vat_country_code.upper())], limit=1) if not vat_has_legit_country_code: vat_has_legit_country_code = vat_country_code.lower() in _region_specific_vat_codes diff --git a/addons/base_vat/tests/test_validate_ruc.py b/addons/base_vat/tests/test_validate_ruc.py index 3cf9f73d640..20371188542 100644 --- a/addons/base_vat/tests/test_validate_ruc.py +++ b/addons/base_vat/tests/test_validate_ruc.py @@ -87,6 +87,11 @@ class TestStructure(TransactionCase): test_partner = self.env['res.partner'].create({'name': "Turlututu", 'country_id': self.env.ref('base.fr').id}) test_partner.write({'vat': "EU528003646", 'country_id': None}) + test_partner.write({'vat': "EU528003646", 'country_id': self.env.ref('base.ca').id}) + + with self.assertRaises(ValidationError): + test_partner.write({'vat': 'EU528003646', 'country_id': self.env.ref('base.be').id}) + @tagged('-standard', 'external') class TestStructureVIES(TestStructure):