Normalize formatted tax identifiers for ID type
Publicar paquete PyPI / publish (push) Successful in 2m54s

This commit is contained in:
José Arturo García
2026-08-23 12:23:37 -04:00
parent 76c18fbc39
commit 54649bb8e9
3 changed files with 54 additions and 11 deletions
+22 -10
View File
@@ -1109,16 +1109,28 @@ class Invoice(metaclass=PoolMeta):
return {'amount_invoiced_goods': amount_invoiced_goods}
def get_id_type(self, name):
if self.party:
if not self.party_tax_identifier:
return None
code_length = len(self.party_tax_identifier.code)
if code_length == 9:
return 1
elif code_length == 11:
return 2
else:
return 3
if not self.party or not self.party_tax_identifier:
return None
identifier = self.party_tax_identifier
identifier_type = getattr(identifier, 'type', None)
if identifier_type in {'do_rnc', 'do_vat'}:
return 1
if identifier_type == 'do_cedula':
return 2
# Tryton 8.0 stores a formatted display code (for example
# ``1-01-01063-2`` or ``001-1391820-5``). Use code_compact when
# available and still normalize it for migrated records whose compact
# value may retain the old formatting.
code = (getattr(identifier, 'code_compact', None)
or getattr(identifier, 'code', None) or '')
digits = re.sub(r'\D', '', code)
if len(digits) == 9:
return 1
if len(digits) == 11:
return 2
return 3
@fields.depends('taxes', 'lines')
def on_change_with_itbis_invoiced(self, name=None):