From 58a2a683ecb6e098c84558b3a7cbcc2976b8a5e9 Mon Sep 17 00:00:00 2001 From: Usdoo Wedoo Date: Fri, 2 Jul 2021 19:16:21 -0500 Subject: [PATCH] [MIG] base_vat_optional_vies: Migration to 14.0 --- base_vat_optional_vies/__manifest__.py | 2 +- base_vat_optional_vies/models/res_partner.py | 11 ++++++----- base_vat_optional_vies/tests/test_res_partner.py | 11 ++++++++++- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/base_vat_optional_vies/__manifest__.py b/base_vat_optional_vies/__manifest__.py index 13a04e31..61ddddb9 100644 --- a/base_vat_optional_vies/__manifest__.py +++ b/base_vat_optional_vies/__manifest__.py @@ -6,7 +6,7 @@ { "name": "Optional validation of VAT via VIES", "category": "Accounting", - "version": "13.0.1.0.1", + "version": "14.0.1.0.0", "depends": ["base_vat"], "external_dependencies": {"python": ["vatnumber"]}, "data": ["views/res_partner_view.xml"], diff --git a/base_vat_optional_vies/models/res_partner.py b/base_vat_optional_vies/models/res_partner.py index bddc3d13..31d82cca 100644 --- a/base_vat_optional_vies/models/res_partner.py +++ b/base_vat_optional_vies/models/res_partner.py @@ -12,10 +12,12 @@ class ResPartner(models.Model): @api.model def simple_vat_check(self, country_code, vat_number): - res = super(ResPartner, self).simple_vat_check(country_code, vat_number,) + res = super(ResPartner, self).simple_vat_check( + country_code, + vat_number, + ) partner = self.env.context.get("vat_partner") - if partner and self.vies_passed: - # Can not be sure that this VAT is signed up in VIES + if partner: partner.update({"vies_passed": False}) return res @@ -27,8 +29,6 @@ class ResPartner(models.Model): # call simple_vat_check and thus the flag will be removed partner.update({"vies_passed": True}) res = super(ResPartner, self).vies_vat_check(country_code, vat_number) - if not res: - return self.simple_vat_check(country_code, vat_number) return res @api.constrains("vat", "country_id") @@ -36,3 +36,4 @@ class ResPartner(models.Model): for partner in self: partner = partner.with_context(vat_partner=partner) super(ResPartner, partner).check_vat() + return True diff --git a/base_vat_optional_vies/tests/test_res_partner.py b/base_vat_optional_vies/tests/test_res_partner.py index 65cbb71b..7149ba1e 100644 --- a/base_vat_optional_vies/tests/test_res_partner.py +++ b/base_vat_optional_vies/tests/test_res_partner.py @@ -13,12 +13,13 @@ class TestResPartner(common.TransactionCase): self.company = self.env.user.company_id self.company.vat_check_vies = True self.partner = self.env["res.partner"].create({"name": "Test partner"}) - self.vatnumber_path = "odoo.addons.base_vat.models.res_partner.vatnumber" + self.vatnumber_path = "odoo.addons.base_vat.models.res_partner.check_vies" def test_validate_vat_vies(self): with mock.patch(self.vatnumber_path) as mock_vatnumber: mock_vatnumber.check_vies.return_value = True self.partner.vat = "ESB87530432" + self.partner.country_id = 20 self.assertEqual(self.partner.vies_passed, True) def test_exception_vat_vies(self): @@ -32,3 +33,11 @@ class TestResPartner(common.TransactionCase): mock_vatnumber.check_vies.return_value = False self.partner.vat = "ESB87530432" self.assertEqual(self.partner.vies_passed, False) + + def test_validate_simple_vat_vies(self): + with mock.patch(self.vatnumber_path) as mock_vatnumber: + self.company.vat_check_vies = False + mock_vatnumber.check_vies.return_value = False + self.partner.vat = "MXGODE561231GR8" + self.partner.country_id = 156 + self.assertEqual(self.partner.vies_passed, False)