2
0

[MIG] base_vat_optional_vies: Migration to 14.0

This commit is contained in:
Usdoo Wedoo 2021-07-02 19:16:21 -05:00 committed by Rodrigo
parent c9fc831081
commit 58a2a683ec
3 changed files with 17 additions and 7 deletions

View File

@ -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"],

View File

@ -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

View File

@ -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)