Fixes to avoid exception when using default _construct_constraint_msg method

This commit is contained in:
Antonio Espinosa
2016-01-05 11:13:40 +01:00
committed by Pedro M. Baeza
parent a00b59717a
commit 10faa187cd
3 changed files with 9 additions and 10 deletions

View File

@@ -19,7 +19,6 @@
'Odoo Community Association (OCA)',
'website': 'http://www.antiun.com',
'license': 'AGPL-3',
'demo': [],
'test': [],
'images': [],
'installable': True,
}

View File

@@ -4,6 +4,9 @@
import logging
import re
from openerp import models, fields, api
from openerp.exceptions import ValidationError
_logger = logging.getLogger(__name__)
try:
@@ -16,9 +19,6 @@ except ImportError:
"`pip install vatnumber`.")
vatnumber = None
from openerp import models, fields, api
from openerp.exceptions import ValidationError
class ResPartner(models.Model):
_inherit = 'res.partner'
@@ -49,7 +49,7 @@ class ResPartner(models.Model):
@summary: Split Partner vat into country_code and number
@result: (vat_country, vat_number)
"""
vat_country = False
vat_country = 'XX'
vat_number = vat
if vat and re.match(r'[A-Za-z]{2}', vat):
vat_country = vat[:2].upper()
@@ -68,10 +68,10 @@ class ResPartner(models.Model):
# quick and partial off-line checksum validation
check_func = self.simple_vat_optional_check
vat_country, vat_number = self._split_vat(self.vat)
if not vat_country:
if vat_number and vat_country == 'XX':
_logger.info("VAT country not found!")
raise ValidationError(self._construct_constraint_msg())
if not check_func(vat_country, vat_number):
if vat_number and not check_func(vat_country, vat_number):
_logger.info("VAT Number [%s] is not valid !" % vat_number)
return False
return True

View File

@@ -18,8 +18,8 @@ class TestResPartner(TransactionCase):
cases = (
# vat, country, => vat_country, vat_number
('ESB12345678', False, 'ES', 'B12345678'),
('B12345678', False, False, 'B12345678'),
('1EB12345678', False, False, '1EB12345678'),
('B12345678', False, 'XX', 'B12345678'),
('1EB12345678', False, 'XX', '1EB12345678'),
('ESB12345678', 'DE', 'ES', 'B12345678'),
('B12345678', 'ES', 'ES', 'B12345678'),
)