Assign payments to non-residents to the dedicated ISREXT group in both localization datasets and tax rules. Add regression checks for national and foreign ISR groups.
73 lines
2.7 KiB
Python
73 lines
2.7 KiB
Python
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
# this repository contains the full copyright notices and license terms.
|
|
|
|
from sql import Table
|
|
from trytond.pool import PoolMeta
|
|
from trytond.transaction import Transaction
|
|
|
|
LEGACY_OBSOLETE_IDS = {
|
|
'do_tax_itbis_8_compra', 'do_tax_itbis_8_venta',
|
|
'do_tax_itbis_9_compra', 'do_tax_itbis_9_venta',
|
|
'do_tax_ret_itbis_2_adq',
|
|
'do_tax_rule_customer_card_acquirer',
|
|
'do_tax_rule_customer_itbis8', 'do_tax_rule_customer_itbis9',
|
|
'do_tax_rule_supplier_itbis8', 'do_tax_rule_supplier_itbis9',
|
|
'do_tc_itbis_compras_8', 'do_tc_itbis_compras_9',
|
|
'do_tc_itbis_retenido_adq',
|
|
'do_tc_itbis_ventas_8', 'do_tc_itbis_ventas_9',
|
|
'do_tcl_itbis8c_cr', 'do_tcl_itbis8c_inv',
|
|
'do_tcl_itbis8v_cr', 'do_tcl_itbis8v_inv',
|
|
'do_tcl_itbis9c_cr', 'do_tcl_itbis9c_inv',
|
|
'do_tcl_itbis9v_cr', 'do_tcl_itbis9v_inv',
|
|
'do_tcl_ret_itbis_adq_cr', 'do_tcl_ret_itbis_adq_inv',
|
|
'do_trline_cust_card_acquirer',
|
|
'do_trline_cust_itbis8', 'do_trline_cust_itbis9',
|
|
'do_trline_supp_itbis8', 'do_trline_supp_itbis9',
|
|
}
|
|
|
|
LOCALIZATION_MODELS = {
|
|
'account.account.template',
|
|
'account.account.type.template',
|
|
'account.tax.code.line.template',
|
|
'account.tax.code.template',
|
|
'account.tax.group',
|
|
'account.tax.rule.line.template',
|
|
'account.tax.rule.template',
|
|
'account.tax.template',
|
|
}
|
|
|
|
|
|
class ModelData(metaclass=PoolMeta):
|
|
__name__ = 'ir.model.data'
|
|
|
|
@classmethod
|
|
def __register__(cls, module_name):
|
|
super().__register__(module_name)
|
|
|
|
if module_name != 'account_do': # pragma: no cover
|
|
return # Defensive guard for composite PoolMeta classes.
|
|
|
|
cls._migrate_localization_identifiers()
|
|
|
|
@classmethod
|
|
def _migrate_localization_identifiers(cls):
|
|
"Preserve pre-language identifiers when upgrading from 8.0.0."
|
|
|
|
cursor = Transaction().connection.cursor()
|
|
table = Table(cls._table)
|
|
cursor.execute(*table.select(
|
|
table.id, table.fs_id,
|
|
where=(table.module == 'account_do')
|
|
& table.model.in_(tuple(LOCALIZATION_MODELS))))
|
|
obsolete = []
|
|
for record_id, fs_id in cursor.fetchall():
|
|
if fs_id in LEGACY_OBSOLETE_IDS:
|
|
obsolete.append(record_id)
|
|
elif not fs_id.endswith(('_en', '_es_419')):
|
|
cursor.execute(*table.update(
|
|
[table.fs_id], [fs_id + '_es_419'],
|
|
where=table.id == record_id))
|
|
if obsolete:
|
|
# Retain referenced historical templates as user-owned records.
|
|
cursor.execute(*table.delete(where=table.id.in_(obsolete)))
|