diff options
| author | oco-odoo <oco@odoo.com> | 2021-03-23 15:29:47 +0000 |
|---|---|---|
| committer | oco-odoo <oco@odoo.com> | 2021-04-02 09:45:24 +0000 |
| commit | 72b7fb15db4df1a3336bc6e90fe60f49877c52f8 (patch) | |
| tree | de67d641390772c696460bb9c493ef9c7e590d7e /addons | |
| parent | 72c29b105bdb4da5b306cd3b48a1683c1bf3e620 (diff) | |
[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#68492
X-original-commit: 4c962437bd59a1e9302d8034e8870880994eb713
Related: odoo/enterprise#17358
Signed-off-by: Cedric Snauwaert (csn) <csn@openerp.com>
Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/base_vat/models/res_partner.py | 7 | ||||
| -rw-r--r-- | addons/base_vat/tests/test_validate_ruc.py | 58 | ||||
| -rw-r--r-- | addons/l10n_be_edi/test_xml_file/efff_test.xml | 6 | ||||
| -rw-r--r-- | addons/l10n_be_edi/tests/test_ubl.py | 2 |
4 files changed, 62 insertions, 11 deletions
diff --git a/addons/base_vat/models/res_partner.py b/addons/base_vat/models/res_partner.py index 2dcbee9d8cb..35ce8f0e4d8 100644 --- a/addons/base_vat/models/res_partner.py +++ b/addons/base_vat/models/res_partner.py @@ -159,10 +159,9 @@ class ResPartner(models.Model): if not check_func(vat_country, vat_number): #if fails, check with country code from country country_code = partner.commercial_partner_id.country_id.code - if country_code: - if not check_func(country_code.lower(), partner.vat): - msg = partner._construct_constraint_msg(country_code.lower()) - raise ValidationError(msg) + if not country_code or not check_func(country_code.lower(), partner.vat): + msg = partner._construct_constraint_msg(country_code.lower() if country_code else None) + raise ValidationError(msg) def _construct_constraint_msg(self, country_code): self.ensure_one() diff --git a/addons/base_vat/tests/test_validate_ruc.py b/addons/base_vat/tests/test_validate_ruc.py index c51433da8ed..b7a3be3fbf6 100644 --- a/addons/base_vat/tests/test_validate_ruc.py +++ b/addons/base_vat/tests/test_validate_ruc.py @@ -55,9 +55,61 @@ class TestStructure(SavepointCase): # reactivate it and correct the vat number with patch('odoo.addons.base_vat.models.res_partner.check_vies', type(self)._vies_check_func): self.env.user.company_id.vat_check_vies = True - with self.assertRaises(ValidationError), self.env.cr.savepoint(): - company.vat = "BE0987654321" # VIES refused, don't fallback on other check - company.vat = "BE0477472701" + + def test_vat_validation(self): + """ Tests VAT validation (both successes and failures), with the different country + detection cases possible. + """ + # Disable VIES; syntactic verification is enough for this test case + self.env.user.company_id.vat_check_vies = False + + 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}) + + 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') diff --git a/addons/l10n_be_edi/test_xml_file/efff_test.xml b/addons/l10n_be_edi/test_xml_file/efff_test.xml index 625bc32737e..de7bbed9ddb 100644 --- a/addons/l10n_be_edi/test_xml_file/efff_test.xml +++ b/addons/l10n_be_edi/test_xml_file/efff_test.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8"?> <Invoice xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlns:ccts="urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-2" xmlns:stat="urn:oasis:names:specification:ubl:schema:xsd:DocumentStatusCode-1.0" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:udt="urn:un:unece:uncefact:data:draft:UnqualifiedDataTypesSchemaModule:2" xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"> <cbc:UBLVersionID>2.0</cbc:UBLVersionID> <cbc:CustomizationID>1.0</cbc:CustomizationID> @@ -13,9 +13,9 @@ <cbc:LineCountNumeric>1</cbc:LineCountNumeric> <cac:AccountingSupplierParty> <cac:Party> - <cbc:EndpointID schemeID="GLN">BE0123456789</cbc:EndpointID> + <cbc:EndpointID schemeID="GLN">BE0477472701</cbc:EndpointID> <cac:PartyIdentification> - <cbc:ID schemeAgencyName="KBO" schemeAgencyID="BE">123456789</cbc:ID> + <cbc:ID schemeAgencyName="KBO" schemeAgencyID="BE">477472701</cbc:ID> </cac:PartyIdentification> <cac:PartyName> <cbc:Name>The best supplier</cbc:Name> diff --git a/addons/l10n_be_edi/tests/test_ubl.py b/addons/l10n_be_edi/tests/test_ubl.py index 388155ac21c..d9632de96e9 100644 --- a/addons/l10n_be_edi/tests/test_ubl.py +++ b/addons/l10n_be_edi/tests/test_ubl.py @@ -7,7 +7,7 @@ class TestUBL(AccountEdiTestCommon): def setUpClass(cls, chart_template_ref='l10n_be.l10nbe_chart_template', edi_format_ref='l10n_be_edi.edi_efff_1'): super().setUpClass(chart_template_ref=chart_template_ref, edi_format_ref=edi_format_ref) - cls.partner_a.vat = 'BE0123456789' + cls.partner_a.vat = 'BE0477472701' def test_invoice_edi_xml(self): invoice = self._create_empty_vendor_bill() |
