Support European VAT number as EAS and VATIN

Closes #14435
This commit is contained in:
Cédric Krier
2025-12-19 09:41:39 +01:00
parent 249e93dc68
commit 543adc9e3f
2 changed files with 50 additions and 7 deletions
+26 -7
View File
@@ -94,21 +94,40 @@ class Identifier(metaclass=PoolMeta):
def iso_6523(self):
return ISO6523_TYPES.get(self.type, '')
@property
def _eas_type(self):
if self.type == 'eu_vat':
code = self.code[:2].lower()
code = (code
.replace('xi', 'gb')
.replace('el', 'gr'))
return f'{code}_vat'
else:
return self.type
@property
def eas_code(self):
return EAS_TYPES.get(self.type, '')
return EAS_TYPES.get(self._eas_type, '')
@property
def eas(self):
if self.eas_code:
if re.match(r'[a-z]{2}_vat', self.type):
country = self.type[:2].replace('gr', 'el')
return f'{country}{self.code}'.lower()
if re.match(r'[a-z]{2}_vat', self._eas_type):
country = self._eas_type[:2].replace('gr', 'el')
if self.type == 'eu_vat':
code = self.code[2:]
else:
code = self.code
return f'{country}{code}'.lower()
else:
return self.code
@property
def vatin(self):
if re.match(r'[a-z]{2}_vat', self.type):
country = self.type[:2].replace('gr', 'el')
return f'{country}{self.code}'.lower()
if re.match(r'[a-z]{2}_vat', self._eas_type):
country = self._eas_type[:2].replace('gr', 'el')
if self.type == 'eu_vat':
code = self.code[2:]
else:
code = self.code
return f'{country}{code}'.lower()
@@ -44,6 +44,7 @@ def get_invoice():
type='be_vat',
code='BE123456789')
type(identifier).iso_6523 = Identifier.iso_6523
type(identifier)._eas_type = Identifier._eas_type
type(identifier).eas = Identifier.eas
type(identifier).unece_code = Identifier.unece_code
party = MagicMock(
@@ -230,5 +231,28 @@ class EdocumentUblTestCase(ModuleTestCase):
schema = etree.XMLSchema(etree.parse(schema_file))
schema.assertValid(invoice_xml)
@with_transaction()
def test_identifier_eas(self):
"Test EAS identifier"
pool = Pool()
Identifier = pool.get('party.identifier')
for type, code, eas_code, eas in [
('gr_vat', '023456783', '9933', 'el023456783'),
('eu_vat', 'EL023456783', '9933', 'el023456783'),
('eu_vat', 'GR023456783', '9933', 'el023456783'),
('be_vat', '0403019261', '9925', 'be0403019261'),
('eu_vat', 'BE0403019261', '9925', 'be0403019261'),
('gb_vat', '980780684', '9932', 'gb980780684'),
('eu_vat', 'GB980780684', '9932', 'gb980780684'),
('eu_vat', 'XI980780684', '9932', 'gb980780684'),
]:
with self.subTest(type=type, code=code):
identifier = Identifier(type=type, code=code)
self.assertEqual(identifier.eas_code, eas_code)
self.assertEqual(identifier.eas, eas)
self.assertEqual(identifier.vatin, eas)
del ModuleTestCase