2
0

[MIG] base_vat_optional_vies: Migration to 16.0

This commit is contained in:
Rodrigo 2023-01-26 15:08:20 +01:00
parent 8042d2b116
commit 46303c4677
3 changed files with 12 additions and 15 deletions

View File

@ -7,7 +7,7 @@
{
"name": "Optional validation of VAT via VIES",
"category": "Accounting",
"version": "15.0.1.0.3",
"version": "16.0.1.0.0",
"depends": ["base_vat"],
"data": ["views/res_partner_view.xml"],
"author": "Tecnativa," "Odoo Community Association (OCA)",

View File

@ -15,23 +15,20 @@ 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,
)
partner = self.env.context.get("vat_partner")
res = super().simple_vat_check(country_code, vat_number)
partner = self._context.get("vat_partner")
if partner:
partner.update({"vies_passed": False})
return res
@api.model
def vies_vat_check(self, country_code, vat_number):
partner = self.env.context.get("vat_partner")
partner = self._context.get("vat_partner")
if partner:
# If there's an exception checking VIES, the upstream method will
# 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)
res = super().vies_vat_check(country_code, vat_number)
if res is False:
if partner:
partner.update({"vies_passed": False})

View File

@ -4,7 +4,7 @@
# Copyright 2022 Moduon - Eduardo de Miguel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import mock
from unittest.mock import patch
from odoo.exceptions import ValidationError
from odoo.tests import common
@ -12,7 +12,7 @@ from odoo.tests import common
class TestResPartner(common.TransactionCase):
def setUp(self):
super(TestResPartner, self).setUp()
super().setUp()
self.company = self.env.user.company_id
self.company.vat_check_vies = True
self.partner = self.env["res.partner"].create(
@ -21,26 +21,26 @@ class TestResPartner(common.TransactionCase):
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:
with patch(self.vatnumber_path) as mock_vatnumber:
mock_vatnumber.check_vies.return_value = True
self.partner.vat = "ESB87530432"
self.partner.country_id = self.env.ref("base.be")
self.assertEqual(self.partner.vies_passed, True)
def test_exception_vat_vies(self):
with mock.patch(self.vatnumber_path) as mock_vatnumber:
with patch(self.vatnumber_path) as mock_vatnumber:
mock_vatnumber.check_vies.side_effect = Exception()
self.partner.vat = "ESB87530432"
self.assertEqual(self.partner.vies_passed, False)
def test_no_validate_vat(self):
with mock.patch(self.vatnumber_path) as mock_vatnumber:
with patch(self.vatnumber_path) as mock_vatnumber:
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:
with patch(self.vatnumber_path) as mock_vatnumber:
self.company.vat_check_vies = False
mock_vatnumber.check_vies.return_value = False
self.partner.vat = "MXGODE561231GR8"
@ -48,7 +48,7 @@ class TestResPartner(common.TransactionCase):
self.assertEqual(self.partner.vies_passed, False)
def test_validate_vies_passed_false_when_vat_set_to_false(self):
with mock.patch(self.vatnumber_path) as mock_vatnumber:
with patch(self.vatnumber_path) as mock_vatnumber:
mock_vatnumber.check_vies.return_value = True
self.partner.vat = "ESB87530432"
self.partner.country_id = self.env.ref("base.be")