Harden localization data and validation

This commit is contained in:
José Arturo García
2026-08-10 08:42:52 -04:00
parent 6f12c82ce1
commit e646947a6e
7 changed files with 132 additions and 85 deletions
+71 -9
View File
@@ -306,7 +306,8 @@ class AccountDoTestCase(ModuleTestCase):
'210218', '210219',
'21020101', '21020102', '21020103', '21020104',
'21020105', '21020201', '21020501', '21020502',
'21020601', '21020701', '21020702', '21020801',
'21020601', '21020701', '21020702', '21020703',
'21020801',
'21020802', '21020803', '21020804', '21020805',
'21020901', '21021001', '21021101', '21021201',
'21021301', '21021302', '21021401', '21021501',
@@ -372,6 +373,13 @@ class AccountDoTestCase(ModuleTestCase):
'ITBIS Withholding Informal Supplier 75%'),
('rate', '=', Decimal('-0.135')),
], limit=1))
foreign_15, = Tax.search([
('company', '=', company.id),
('description', '=', 'Foreign ISR Withholding 15%'),
], limit=1)
self.assertEqual(foreign_15.rate, Decimal('-0.15'))
self.assertEqual(
foreign_15.start_date, datetime.date(2026, 7, 1))
check_015, = Tax.search([
('company', '=', company.id),
('description', '=', 'Checks and Transfers Tax 0.15%'),
@@ -398,6 +406,43 @@ class AccountDoTestCase(ModuleTestCase):
'date': datetime.date(2026, 7, 3),
}),
[check_020.id])
foreign_27, = Tax.search([
('company', '=', company.id),
('description', '=', 'Foreign ISR Withholding 27%'),
], limit=1)
foreign_rule, = TaxRule.search([
('company', '=', company.id),
('name', '=', (
'Foreign Royalties, Software and Online '
'Services 15% Rule (RD)')),
], limit=1)
self.assertEqual(
foreign_rule.apply(foreign_27, {
'date': datetime.date(2026, 6, 30),
}),
[foreign_27.id])
self.assertEqual(
foreign_rule.apply(foreign_27, {
'date': datetime.date(2026, 7, 1),
}),
[foreign_15.id])
itbis_sale, = Tax.search([
('company', '=', company.id),
('description', '=', 'ITBIS 18% Sales'),
], limit=1)
society_withholding, = Tax.search([
('company', '=', company.id),
('description', '=', 'ITBIS Withheld Companies 30%'),
], limit=1)
society_rule, = TaxRule.search([
('company', '=', company.id),
('name', '=', (
'ITBIS Withheld by Companies 30% Customer '
'Rule (RD)')),
], limit=1)
self.assertEqual(
society_rule.apply(itbis_sale, {}),
[society_withholding.id, itbis_sale.id])
real_tax_code_signs = {
('ITBIS 18% Sales', 'invoice'): '+',
('ITBIS 18% Sales', 'credit'): '-',
@@ -560,11 +605,11 @@ class AccountDoUnitTestCase(unittest.TestCase):
'account.account.template': 282,
},
'tax_do_en.xml': {
'account.tax.group': 7,
'account.tax.group': 6,
'account.tax.template': 51,
},
'tax_code_do_en.xml': {
'account.tax.code.template': 44,
'account.tax.code.template': 43,
'account.tax.code.line.template': 95,
},
'tax_rule_do_en.xml': {
@@ -576,11 +621,11 @@ class AccountDoUnitTestCase(unittest.TestCase):
'account.account.template': 282,
},
'tax_do_es_419.xml': {
'account.tax.group': 7,
'account.tax.group': 6,
'account.tax.template': 51,
},
'tax_code_do_es_419.xml': {
'account.tax.code.template': 44,
'account.tax.code.template': 43,
'account.tax.code.line.template': 95,
},
'tax_rule_do_es_419.xml': {
@@ -629,13 +674,17 @@ class AccountDoUnitTestCase(unittest.TestCase):
'tax_code_do_en.xml', 'tax_rule_do_en.xml']
for field in ET.parse(MODULE_DIR / filename).getroot().findall(
'.//field')
if field.get('name') in {'name', 'description'} and field.text)
if field.get('name') in {
'name', 'description', 'legal_notice'} and field.text)
for phrase in [
'advance itbis', 'assets for right of use',
'charged for paying', 'clients tax rule',
'collected to pay', 'deterioration', 'in favor',
'itbis supported', 'other income and profits',
'physical persons', 'retention', 'withheld status',
' aseguradoras ', ' bienes ', ' casilla ',
' combustibles ', ' intereses ', ' ley ', ' pagos ',
' personas ', ' premios ', ' retención ', ' tasa ',
]:
with self.subTest(phrase=phrase):
self.assertNotIn(phrase, text.lower())
@@ -722,6 +771,19 @@ class AccountDoUnitTestCase(unittest.TestCase):
field.get('name'), ref))
self.assertEqual(missing, [])
def test_every_tax_group_is_used(self):
"""Do not install tax groups that no tax template can produce."""
records = list(_iter_xml_records('tax_do_en.xml'))
groups = {
record_id for _, record_id, model, _values in records
if model == 'account.tax.group'
}
used_groups = {
values['group'] for _, _, model, values in records
if model == 'account.tax.template' and values.get('group')
}
self.assertEqual(groups, used_groups)
def test_chart_template_codes_are_unique(self):
accounts = [
values for _, _, model, values in _iter_xml_records(
@@ -878,13 +940,13 @@ class AccountDoUnitTestCase(unittest.TestCase):
taxes['do_tax_ret_isr_bovine_1']['start_date'],
'datetime.date(2025, 6, 20)')
self.assertIn(
'arts. 401-405; art. 404',
'Tax Code Arts. 401-405; Art. 404',
taxes['do_tax_activos_1']['legal_notice'])
self.assertIn(
'art. 7 Ley 173-07',
'Law 173-07 Art. 7',
taxes['do_tax_iti_3']['legal_notice'])
self.assertIn(
'art. 228', taxes['do_tax_propina_10']['legal_notice'])
'Art. 228', taxes['do_tax_propina_10']['legal_notice'])
self.assertEqual(
taxes['do_tax_isc_vehiculos']['group'],
'do_tax_group_others')