Skip to content

Commit

Permalink
[MIG] base_vat_optional_vies: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoBM committed Jan 26, 2023
1 parent d62e194 commit 5dec75f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion base_vat_optional_vies/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
11 changes: 4 additions & 7 deletions base_vat_optional_vies/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
14 changes: 7 additions & 7 deletions base_vat_optional_vies/tests/test_res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
# 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


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(
Expand All @@ -21,34 +21,34 @@ def setUp(self):
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"
self.partner.country_id = self.env.ref("base.mx")
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")
Expand Down

0 comments on commit 5dec75f

Please sign in to comment.