[FIX] base_vat: allow tax IDs starting with 'EU' for non EU countries
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 <jco@odoo.com> Signed-off-by: Séna Serge Nshimiyimana (sesn) <sesn@odoo.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user