134 lines
4.2 KiB
Python
134 lines
4.2 KiB
Python
from trytond.model import fields
|
||
from trytond.pool import PoolMeta
|
||
from trytond.transaction import Transaction
|
||
from sql import Null, Table
|
||
|
||
TAX_KIND = [
|
||
('', ''),
|
||
('itbis', 'ITBIS'),
|
||
('itbis_withholding', 'Retención ITBIS'),
|
||
('itbis_withholding_acquirer', 'Retención ITBIS Adquirentes'),
|
||
('isr_withholding', 'Retención ISR'),
|
||
('isc', 'ISC — Selectivo al Consumo'),
|
||
('cdt', 'CDT INDOTEL'),
|
||
('tip', 'Propina Legal'),
|
||
('others', 'Other Taxes'),
|
||
]
|
||
|
||
MODEL_DATA_RENAMES = {
|
||
'do_tax_group_otros': 'do_tax_group_others',
|
||
'do_tc_otros': 'do_tc_others',
|
||
'do_tc_otros_propina': 'do_tc_others_tip',
|
||
'do_tc_otros_cheques': 'do_tc_others_checks',
|
||
'do_tc_otros_activos': 'do_tc_others_assets',
|
||
'do_tc_otros_iti': 'do_tc_others_iti',
|
||
}
|
||
|
||
ROOT_TAX_CODE_CHILDREN = [
|
||
'ITBIS — Balance Neto (Débito − Crédito)',
|
||
'ISR - Retenciones',
|
||
'ISR - Retenciones en la Fuente',
|
||
'ISC - Impuesto Selectivo al Consumo',
|
||
'CDT INDOTEL 2% (Ley 153-98)',
|
||
'Otros Impuestos y Contribuciones',
|
||
]
|
||
|
||
|
||
def migrate_model_data_names(cursor, module_name):
|
||
if module_name != 'account_do':
|
||
return
|
||
model_data = Table('ir_model_data')
|
||
for old, new in MODEL_DATA_RENAMES.items():
|
||
cursor.execute(*model_data.update(
|
||
[model_data.fs_id], [new],
|
||
where=(model_data.module == module_name)
|
||
& (model_data.fs_id == old)))
|
||
|
||
|
||
class TaxTemplate(metaclass=PoolMeta):
|
||
__name__ = 'account.tax.template'
|
||
|
||
tax_kind = fields.Selection(TAX_KIND, 'Tax Kind', sort=False)
|
||
|
||
@classmethod
|
||
def __register__(cls, module_name):
|
||
cursor = Transaction().connection.cursor()
|
||
table = cls.__table__()
|
||
|
||
super().__register__(module_name)
|
||
|
||
migrate_model_data_names(cursor, module_name)
|
||
cursor.execute(*table.update(
|
||
[table.tax_kind], ['others'],
|
||
where=table.tax_kind == 'otros'))
|
||
|
||
def _get_tax_value(self, tax=None):
|
||
values = super()._get_tax_value(tax=tax)
|
||
if not tax or tax.tax_kind != self.tax_kind:
|
||
values['tax_kind'] = self.tax_kind
|
||
return values
|
||
|
||
|
||
class Tax(metaclass=PoolMeta):
|
||
__name__ = 'account.tax'
|
||
|
||
tax_kind = fields.Selection(TAX_KIND, 'Tax Kind', sort=False)
|
||
|
||
@classmethod
|
||
def __register__(cls, module_name):
|
||
cursor = Transaction().connection.cursor()
|
||
table = cls.__table__()
|
||
|
||
super().__register__(module_name)
|
||
|
||
cursor.execute(*table.update(
|
||
[table.tax_kind], ['others'],
|
||
where=table.tax_kind == 'otros'))
|
||
|
||
|
||
class TaxCode(metaclass=PoolMeta):
|
||
__name__ = 'account.tax.code'
|
||
|
||
@classmethod
|
||
def __register__(cls, module_name):
|
||
cursor = Transaction().connection.cursor()
|
||
|
||
super().__register__(module_name)
|
||
|
||
if module_name != 'account_do':
|
||
return
|
||
table = cls.__table__()
|
||
cursor.execute(*table.update(
|
||
[table.name], ['ISR - Retenciones'],
|
||
where=table.name == 'ISR - Retenciones en la Fuente'))
|
||
cursor.execute(*table.update(
|
||
[table.parent], [None],
|
||
where=table.name.in_(ROOT_TAX_CODE_CHILDREN)
|
||
& table.parent.in_(table.select(table.id,
|
||
where=table.name == 'Impuestos República Dominicana'))))
|
||
|
||
|
||
class TaxCodeLine(metaclass=PoolMeta):
|
||
__name__ = 'account.tax.code.line'
|
||
|
||
@classmethod
|
||
def __register__(cls, module_name):
|
||
cursor = Transaction().connection.cursor()
|
||
|
||
super().__register__(module_name)
|
||
|
||
if module_name != 'account_do':
|
||
return
|
||
line = cls.__table__()
|
||
code = Table('account_tax_code')
|
||
tax = Table('account_tax')
|
||
cursor.execute(*line.delete(
|
||
where=(line.template == Null)
|
||
& line.code.in_(code.select(code.id,
|
||
where=code.name == (
|
||
'Retención ISR Intereses 1% '
|
||
'(Personas Jurídicas, NG 07-19)')))
|
||
& line.tax.in_(tax.select(tax.id,
|
||
where=tax.description == (
|
||
'Retención ISR Intereses Persona Física 10%')))))
|