212 lines
8.2 KiB
Python
212 lines
8.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'),
|
||
]
|
||
|
||
TAX_FISCAL_TYPE = [
|
||
('', ''),
|
||
('itbis_sale_18', 'ITBIS ventas 18%'),
|
||
('itbis_sale_16', 'ITBIS ventas 16%'),
|
||
('itbis_sale_9', 'ITBIS ventas 9%'),
|
||
('itbis_sale_8', 'ITBIS ventas 8%'),
|
||
('itbis_purchase_18', 'ITBIS compras 18%'),
|
||
('itbis_purchase_16', 'ITBIS compras 16%'),
|
||
('itbis_purchase_9', 'ITBIS compras 9%'),
|
||
('itbis_purchase_8', 'ITBIS compras 8%'),
|
||
('itbis_exempt', 'ITBIS exento'),
|
||
('itbis_zero_rate', 'ITBIS tasa cero'),
|
||
('itbis_withholding_30', 'Retención ITBIS 30%'),
|
||
('itbis_withholding_75_informal', 'Retención ITBIS 75% proveedor informal'),
|
||
('itbis_withholding_75_informal_16', 'Retención ITBIS 75% proveedor informal 16%'),
|
||
('itbis_withholding_100_services', 'Retención ITBIS 100% servicios'),
|
||
('itbis_withholding_100_informal_goods_18', 'Retención ITBIS 100% bienes informales 18%'),
|
||
('itbis_withholding_100_informal_goods_16', 'Retención ITBIS 100% bienes informales 16%'),
|
||
('itbis_withholding_rst_18', 'Retención ITBIS RST 18%'),
|
||
('itbis_withholding_rst_16', 'Retención ITBIS RST 16%'),
|
||
('itbis_withholding_insurance_100', 'Retención ITBIS seguros 100%'),
|
||
('itbis_withholding_airline_100', 'ITBIS retenido aerolíneas 100%'),
|
||
('itbis_withholding_society_30_suffered', 'ITBIS retenido sociedades 30%'),
|
||
('itbis_withholding_hotel_100', 'ITBIS retenido hoteles 100%'),
|
||
('itbis_withholding_state_100', 'ITBIS retenido Estado 100%'),
|
||
('itbis_withholding_acquirer_2', 'Retención ITBIS adquirencia 2%'),
|
||
('isr_legal_entity_services_5', 'ISR servicios personas jurídicas 5%'),
|
||
('isr_individual_services_10', 'ISR servicios personas físicas 10%'),
|
||
('isr_dividends_10', 'ISR dividendos 10%'),
|
||
('isr_interest_individual_10', 'ISR intereses personas físicas 10%'),
|
||
('isr_interest_legal_entity_1', 'ISR intereses personas jurídicas 1%'),
|
||
('isr_rent_10', 'ISR alquileres 10%'),
|
||
('isr_state_1_5', 'ISR pagos del Estado 1.5%'),
|
||
('isr_state_5', 'ISR pagos del Estado 5%'),
|
||
('isr_bovine_meat_1', 'ISR ganadería/carne bovina 1%'),
|
||
('isr_exporter_sales_2_5', 'ISR exportadores ventas mercado local 2.5%'),
|
||
('isr_prizes_10', 'ISR premios 10%'),
|
||
('isr_prizes_15', 'ISR premios 15%'),
|
||
('isr_prizes_25', 'ISR premios 25%'),
|
||
('isr_slot_machine_prizes_10', 'ISR premios máquinas tragamonedas 10%'),
|
||
('isr_other_income_10', 'ISR otras rentas 10%'),
|
||
('isr_foreign_services_27', 'ISR exterior servicios/regalías 27%'),
|
||
('isr_foreign_interest_10', 'ISR exterior intereses/asistencia 10%'),
|
||
('isc_alcohol_10', 'ISC bebidas alcohólicas 10%'),
|
||
('isc_tobacco_20', 'ISC tabaco 20%'),
|
||
('isc_telecom_10', 'ISC telecomunicaciones 10%'),
|
||
('isc_fossil_fuel_16', 'ISC combustibles fósiles 16%'),
|
||
('isc_avtur_6_5', 'ISC Avtur 6.5%'),
|
||
('isc_fuel_rd2_gallon', 'ISC adicional combustibles RD$2 por galón'),
|
||
('isc_insurance_withholding_100', 'Retención ISC seguros 100%'),
|
||
('isc_vehicle_17', 'ISC vehículos 17% referencial'),
|
||
('cdt_indotel_2', 'CDT INDOTEL 2%'),
|
||
('legal_tip_10', 'Propina legal 10%'),
|
||
('check_transfer_tax_015', 'Impuesto cheques/transferencias 0.15%'),
|
||
('check_transfer_tax_020', 'Impuesto cheques/transferencias 0.20%'),
|
||
('asset_tax_1', 'Impuesto a los activos 1%'),
|
||
('real_estate_transfer_3', 'Transferencia inmobiliaria 3%'),
|
||
]
|
||
|
||
TAX_APPLICATION = [
|
||
('', ''),
|
||
('sale_invoice', 'Factura de venta'),
|
||
('purchase_invoice', 'Factura de compra'),
|
||
('payment_withholding', 'Retención en pago/cobro'),
|
||
('bank_charge', 'Cargo bancario'),
|
||
('annual_declaration', 'Declaración anual'),
|
||
('asset_transfer', 'Transferencia de activos'),
|
||
]
|
||
|
||
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)
|
||
tax_fiscal_type = fields.Selection(
|
||
TAX_FISCAL_TYPE, 'Fiscal Tax Type', sort=False)
|
||
tax_application = fields.Selection(
|
||
TAX_APPLICATION, 'Tax Application', 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)
|
||
for field in ['tax_kind', 'tax_fiscal_type', 'tax_application']:
|
||
if not tax or getattr(tax, field) != getattr(self, field):
|
||
values[field] = getattr(self, field)
|
||
return values
|
||
|
||
|
||
class Tax(metaclass=PoolMeta):
|
||
__name__ = 'account.tax'
|
||
|
||
tax_kind = fields.Selection(TAX_KIND, 'Tax Kind', sort=False)
|
||
tax_fiscal_type = fields.Selection(
|
||
TAX_FISCAL_TYPE, 'Fiscal Tax Type', sort=False)
|
||
tax_application = fields.Selection(
|
||
TAX_APPLICATION, 'Tax Application', 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%')))))
|