diff options
Diffstat (limited to 'addons/base_vat/tests/test_validate_ruc.py')
| -rw-r--r-- | addons/base_vat/tests/test_validate_ruc.py | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/addons/base_vat/tests/test_validate_ruc.py b/addons/base_vat/tests/test_validate_ruc.py index 9f65d5aab37..c51433da8ed 100644 --- a/addons/base_vat/tests/test_validate_ruc.py +++ b/addons/base_vat/tests/test_validate_ruc.py @@ -1,11 +1,20 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo.tests import common +from odoo.tests.common import SavepointCase, tagged from odoo.exceptions import ValidationError from unittest.mock import patch -from stdnum.eu import vat +import stdnum.eu.vat -class TestStructure(common.TransactionCase): + +class TestStructure(SavepointCase): + @classmethod + def setUpClass(cls): + def check_vies(vat_number): + return {'valid': vat_number == 'BE0477472701'} + + super().setUpClass() + cls.env.user.company_id.vat_check_vies = False + cls._vies_check_func = check_vies def test_peru_ruc_format(self): """Only values that has the length of 11 will be checked as RUC, that's what we are proving. The second part @@ -29,7 +38,7 @@ class TestStructure(common.TransactionCase): def test_parent_validation(self): """Test the validation with company and contact""" - # disable the verification to set an invalid vat number + # set an invalid vat number self.env.user.company_id.vat_check_vies = False company = self.env["res.partner"].create({ "name": "World Company", @@ -43,11 +52,18 @@ class TestStructure(common.TransactionCase): "company_type": "person", }) - def mock_check_vies(vat_number): - """ Fake vatnumber method that will only allow one number """ - return vat_number == 'BE0987654321' - # reactivate it and correct the vat number - with patch.object(vat, 'check_vies', mock_check_vies): + 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 - company.vat = "BE0987654321" + with self.assertRaises(ValidationError), self.env.cr.savepoint(): + company.vat = "BE0987654321" # VIES refused, don't fallback on other check + company.vat = "BE0477472701" + + +@tagged('-standard', 'external') +class TestStructureVIES(TestStructure): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env.user.company_id.vat_check_vies = True + cls._vies_check_func = stdnum.eu.vat.check_vies |
