mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Fixes to avoid exception when using default _construct_constraint_msg method
This commit is contained in:
committed by
Pedro M. Baeza
parent
a00b59717a
commit
10faa187cd
@@ -19,7 +19,6 @@
|
||||
'Odoo Community Association (OCA)',
|
||||
'website': 'http://www.antiun.com',
|
||||
'license': 'AGPL-3',
|
||||
'demo': [],
|
||||
'test': [],
|
||||
'images': [],
|
||||
'installable': True,
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user