Files
odoo_source/addons/base_vat/tests/test_validate_ruc.py
T
wan 5783642ee4 [FIX] base_vat: not called at all
The function was wrongly imported and used, and it was hidden by a
generic catching of all exceptions.
The return value and some legit exceptions were also badly handled:
* The return value was always thruthy as it returns an object containing
information about the check.
* Exceptions can be raised if the format is not correct. In that case,
we don't want to go to the simple vat check.

Fixes #64897
opw-2451951

closes odoo/odoo#66522

X-original-commit: e711f359fef7ed4c37cb26d3946744e140bf00e0
Signed-off-by: William André (wan) <wan@odoo.com>
2021-02-19 09:50:24 +00:00

70 lines
2.6 KiB
Python

# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests.common import TransactionCase, tagged
from odoo.exceptions import ValidationError
from unittest.mock import patch
import stdnum.eu.vat
class TestStructure(TransactionCase):
@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
will check for a valid ruc and there will be no problem at all.
"""
partner = self.env['res.partner'].create({'name': "Dummy partner", 'country_id': self.env.ref('base.pe').id})
with self.assertRaises(ValidationError):
partner.vat = '11111111111'
partner.vat = '20507822470'
def test_vat_country_difference(self):
"""Test the validation when country code is different from vat code"""
partner = self.env['res.partner'].create({
'name': "Test",
'country_id': self.env.ref('base.mx').id,
'vat': 'RORO790707I47',
})
self.assertEqual(partner.vat, 'RORO790707I47', "Partner VAT should not be altered")
def test_parent_validation(self):
"""Test the validation with company and contact"""
# set an invalid vat number
self.env.user.company_id.vat_check_vies = False
company = self.env["res.partner"].create({
"name": "World Company",
"country_id": self.env.ref("base.be").id,
"vat": "ATU12345675",
"company_type": "company",
})
contact = self.env["res.partner"].create({
"name": "Sylvestre",
"parent_id": company.id,
"company_type": "person",
})
# reactivate it and correct the vat number
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
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