Normalize formatted tax identifiers for ID type
Publicar paquete PyPI / publish (push) Successful in 2m54s
Publicar paquete PyPI / publish (push) Successful in 2m54s
This commit is contained in:
+18
-6
@@ -1109,15 +1109,27 @@ class Invoice(metaclass=PoolMeta):
|
|||||||
return {'amount_invoiced_goods': amount_invoiced_goods}
|
return {'amount_invoiced_goods': amount_invoiced_goods}
|
||||||
|
|
||||||
def get_id_type(self, name):
|
def get_id_type(self, name):
|
||||||
if self.party:
|
if not self.party or not self.party_tax_identifier:
|
||||||
if not self.party_tax_identifier:
|
|
||||||
return None
|
return None
|
||||||
code_length = len(self.party_tax_identifier.code)
|
|
||||||
if code_length == 9:
|
identifier = self.party_tax_identifier
|
||||||
|
identifier_type = getattr(identifier, 'type', None)
|
||||||
|
if identifier_type in {'do_rnc', 'do_vat'}:
|
||||||
return 1
|
return 1
|
||||||
elif code_length == 11:
|
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 2
|
||||||
else:
|
|
||||||
return 3
|
return 3
|
||||||
|
|
||||||
@fields.depends('taxes', 'lines')
|
@fields.depends('taxes', 'lines')
|
||||||
|
|||||||
@@ -370,6 +370,37 @@ del ModuleTestCase
|
|||||||
|
|
||||||
class NcfManagerUnitTestCase(unittest.TestCase):
|
class NcfManagerUnitTestCase(unittest.TestCase):
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def invoice_with_identifier(code, type=None, code_compact=None):
|
||||||
|
identifier = SimpleNamespace(code=code, type=type)
|
||||||
|
if code_compact is not None:
|
||||||
|
identifier.code_compact = code_compact
|
||||||
|
return SimpleNamespace(
|
||||||
|
party=object(), party_tax_identifier=identifier)
|
||||||
|
|
||||||
|
def test_id_type_accepts_formatted_rnc(self):
|
||||||
|
invoice = self.invoice_with_identifier('1-01-01063-2')
|
||||||
|
self.assertEqual(Invoice.get_id_type(invoice, 'id_type'), 1)
|
||||||
|
|
||||||
|
def test_id_type_accepts_formatted_cedula(self):
|
||||||
|
invoice = self.invoice_with_identifier('001-1391820-5')
|
||||||
|
self.assertEqual(Invoice.get_id_type(invoice, 'id_type'), 2)
|
||||||
|
|
||||||
|
def test_id_type_uses_dominican_identifier_type(self):
|
||||||
|
rnc = self.invoice_with_identifier('formatted', type='do_vat')
|
||||||
|
cedula = self.invoice_with_identifier('formatted', type='do_cedula')
|
||||||
|
self.assertEqual(Invoice.get_id_type(rnc, 'id_type'), 1)
|
||||||
|
self.assertEqual(Invoice.get_id_type(cedula, 'id_type'), 2)
|
||||||
|
|
||||||
|
def test_id_type_normalizes_migrated_compact_code(self):
|
||||||
|
invoice = self.invoice_with_identifier(
|
||||||
|
'display value', code_compact='001-1391820-5')
|
||||||
|
self.assertEqual(Invoice.get_id_type(invoice, 'id_type'), 2)
|
||||||
|
|
||||||
|
def test_id_type_returns_none_without_identifier(self):
|
||||||
|
invoice = SimpleNamespace(party=object(), party_tax_identifier=None)
|
||||||
|
self.assertIsNone(Invoice.get_id_type(invoice, 'id_type'))
|
||||||
|
|
||||||
def test_invoice_report_uses_current_tax_field_names(self):
|
def test_invoice_report_uses_current_tax_field_names(self):
|
||||||
path = Path(__file__).parents[1] / 'invoice.fodt'
|
path = Path(__file__).parents[1] / 'invoice.fodt'
|
||||||
template = path.read_text(encoding='utf-8')
|
template = path.read_text(encoding='utf-8')
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
[tryton]
|
[tryton]
|
||||||
version=8.0.0
|
version=8.0.1
|
||||||
depends:
|
depends:
|
||||||
account_do
|
account_do
|
||||||
account_invoice_do
|
account_invoice_do
|
||||||
|
|||||||
Reference in New Issue
Block a user