[FIX] base_vat: Don't always pass VAT check when validating the VAT of a partner without country_id

Before this, when making a partner without any country_id, any VAT could be set to it, which was inconsistent with the module's purpose.

closes odoo/odoo#68815

X-original-commit: 72606f14d0c1d86d7a205fd29aec8d66d3e98678
Related: odoo/enterprise#17505
Signed-off-by: Cedric Snauwaert (csn) <csn@openerp.com>
Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com>
This commit is contained in:
oco-odoo
2021-04-07 09:46:58 +00:00
parent 33bba28e87
commit e68873fe89
2 changed files with 29 additions and 3 deletions
@@ -59,6 +59,32 @@ class TestStructure(TransactionCase):
company.vat = "BE0987654321" # VIES refused, don't fallback on other check
company.vat = "BE0477472701"
def test_vat_syntactic_validation(self):
""" Tests VAT validation (both successes and failures), with the different country
detection cases possible.
"""
test_partner = self.env['res.partner'].create({'name': "John Dex"})
# VAT starting with country code: use the starting country code
test_partner.write({'vat': 'BE0477472701', 'country_id': self.env.ref('base.fr').id})
test_partner.write({'vat': 'BE0477472701', 'country_id': None})
with self.assertRaises(ValidationError):
test_partner.write({'vat': 'BE42', 'country_id': self.env.ref('base.fr').id})
with self.assertRaises(ValidationError):
test_partner.write({'vat': 'BE42', 'country_id': None})
# No country code in VAT: use the partner's country
test_partner.write({'vat': '0477472701', 'country_id': self.env.ref('base.be').id})
with self.assertRaises(ValidationError):
test_partner.write({'vat': '42', 'country_id': self.env.ref('base.be').id})
# If no country can be guessed: VAT number cannot be validated
with self.assertRaises(ValidationError):
test_partner.write({'vat': '0477472701', 'country_id': None})
@tagged('-standard', 'external')
class TestStructureVIES(TestStructure):
+3 -3
View File
@@ -383,12 +383,12 @@ class TestBase(TransactionCase):
for p in (p0, p1, p11, p2, p3):
self.assertEqual(p.commercial_partner_id, sunhelm, 'Incorrect commercial entity resolution')
self.assertEqual(p.vat, sunhelm.vat, 'Commercial fields must be automatically synced')
sunhelmvat = 'BE0123456789'
sunhelmvat = 'BE0123456749'
sunhelm.write({'vat': sunhelmvat})
for p in (p0, p1, p11, p2, p3):
self.assertEqual(p.vat, sunhelmvat, 'Commercial fields must be automatically and recursively synced')
p1vat = 'BE0987654321'
p1vat = 'BE0987654394'
p1.write({'vat': p1vat})
for p in (sunhelm, p0, p11, p2, p3):
self.assertEqual(p.vat, sunhelmvat, 'Sync to children should only work downstream and on commercial entities')
@@ -401,7 +401,7 @@ class TestBase(TransactionCase):
self.assertEqual(p1.commercial_partner_id, p1, 'Incorrect commercial entity resolution after setting is_company')
# writing on parent should not touch child commercial entities
sunhelmvat2 = 'BE0112233445'
sunhelmvat2 = 'BE0112233453'
sunhelm.write({'vat': sunhelmvat2})
self.assertEqual(p1.vat, p1vat, 'Setting is_company should stop auto-sync of commercial fields')
self.assertEqual(p0.vat, sunhelmvat2, 'Commercial fields must be automatically synced')