diff --git a/addons/base_vat/tests/test_validate_ruc.py b/addons/base_vat/tests/test_validate_ruc.py index f542e794887..d7f3eccbbb7 100644 --- a/addons/base_vat/tests/test_validate_ruc.py +++ b/addons/base_vat/tests/test_validate_ruc.py @@ -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): diff --git a/odoo/addons/base/tests/test_base.py b/odoo/addons/base/tests/test_base.py index 15d9108c08f..98ad34afb51 100644 --- a/odoo/addons/base/tests/test_base.py +++ b/odoo/addons/base/tests/test_base.py @@ -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')