Before this commit, a lot of leftover import shims existed in the codebase for py2-py3 compatibility, these are no longer needed since Odoo 13.0+ doesn't support Python 2 anymore and is (finally) in EOL. With this commit, these shims are dropped, making the code cleaner, easier to read and with one less dependency. Queue -> queue -> py2-py3 compatibility xmlrpclib -> xmlrpc.client -> py2-py3 compatibility ConfigParser -> configparser -> py2-py3 compatibility itertools.izip_longest -> itertools.zip_longest -> py2-py3 compatibility urllib -> urllib.request -> py2-py3 compatibility __builtins__ -> builtins -> py2-py3 compatibility _winreg -> winreg -> py2-py3 compatibility mock -> unittest.mock -> merged into CPython The debian/fedora packages and requirements.txt have been updated accordingly closes odoo/odoo#44601 Related: odoo/enterprise#8141 Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
54 lines
2.1 KiB
Python
54 lines
2.1 KiB
Python
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
from odoo.tests import common
|
|
from odoo.exceptions import ValidationError
|
|
from unittest.mock import patch
|
|
|
|
from stdnum.eu import vat
|
|
|
|
class TestStructure(common.TransactionCase):
|
|
|
|
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"""
|
|
|
|
# disable the verification to 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",
|
|
})
|
|
|
|
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):
|
|
self.env.user.company_id.vat_check_vies = True
|
|
company.vat = "BE0987654321"
|