Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 31 additions & 22 deletions l10n_ar_tax/models/account_chart_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def _add_wh_taxes(self, company):
]
for tax_ref, state_ref in tax_state_tupples:
# Identificamos el impuesto al que se le va a agregar la/s etiqueta/s
tax = self.env.ref("account.%s_%s" % (company.id, tax_ref), raise_if_not_found=False)
if tax:
tax.l10n_ar_state_id = self.env.ref(state_ref).id
if tax := self.env.ref("account.%s_%s" % (company.id, tax_ref), raise_if_not_found=False):
if not tax.l10n_ar_state_id:
tax.l10n_ar_state_id = self.env.ref(state_ref).id

# creacion de secuencias y agregado de etiquetas para liquidación de impuestos
withholdings_domain = [
Expand All @@ -85,31 +85,36 @@ def _add_wh_taxes(self, company):
non_profits_domain = withholdings_domain + [("l10n_ar_tax_type", "not in", ["earnings", "earnings_scale"])]

for tax in self.env["account.tax"].with_context(active_test=False).search(non_profits_domain):
if not tax.l10n_ar_withholding_sequence_id:
sequence_name = (tax.invoice_label or tax.name).replace("0", "").replace("%", "")
sequence = self.env["ir.sequence"].create(
{
"name": sequence_name,
"prefix": "%(year)s-",
"padding": 8,
"number_increment": 1,
"implementation": "standard",
"company_id": company.id,
}
)
tax.l10n_ar_withholding_sequence_id = sequence.id

profits_domain = withholdings_domain + [("l10n_ar_tax_type", "in", ["earnings", "earnings_scale"])]
profits_taxes = self.env["account.tax"].with_context(active_test=False).search(profits_domain)
# Todos los impuestos de retención de ganancias deben compartir la misma secuencia
if not all(prof_tax.l10n_ar_withholding_sequence_id for prof_tax in profits_taxes):
sequence = self.env["ir.sequence"].create(
Comment thread
pablohmontenegro marked this conversation as resolved.
Comment thread
pablohmontenegro marked this conversation as resolved.
{
"name": tax.invoice_label or tax.name,
"name": "Retención de Ganancias",
Comment thread
pablohmontenegro marked this conversation as resolved.
"prefix": "%(year)s-",
"padding": 8,
"number_increment": 1,
"implementation": "standard",
"company_id": company.id,
}
)
tax.l10n_ar_withholding_sequence_id = sequence.id

profits_domain = withholdings_domain + [("l10n_ar_tax_type", "in", ["earnings", "earnings_scale"])]
sequence = self.env["ir.sequence"].create(
{
"name": "Retención de Ganancias",
"prefix": "%(year)s-",
"padding": 8,
"number_increment": 1,
"implementation": "standard",
"company_id": company.id,
}
)
profits_taxes = self.env["account.tax"].with_context(active_test=False).search(profits_domain)
profits_taxes.l10n_ar_withholding_sequence_id = sequence.id
for prof_tax in profits_taxes.filtered(lambda tax: not tax.l10n_ar_withholding_sequence_id):
prof_tax.l10n_ar_withholding_sequence_id = sequence.id
Comment on lines +116 to +117
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acá se escribe la secuencia por impuesto en un bucle, lo que genera múltiples writes cuando podría hacerse en una sola operación sobre el recordset filtrado. Para mejorar performance y reducir trazabilidad/locks, asignar el sequence.id directamente al recordset de impuestos sin secuencia (sin iterar).

Suggested change
for prof_tax in profits_taxes.filtered(lambda tax: not tax.l10n_ar_withholding_sequence_id):
prof_tax.l10n_ar_withholding_sequence_id = sequence.id
profits_taxes.filtered(lambda tax: not tax.l10n_ar_withholding_sequence_id).l10n_ar_withholding_sequence_id = sequence.id

Copilot uses AI. Check for mistakes.

# agregado de etiquetas para liquidacion de impuestos sicore
sicore_taxes = profits_taxes
Expand All @@ -121,9 +126,11 @@ def _add_wh_taxes(self, company):
tax = self.env.ref(xml_id_percep, raise_if_not_found=False)
if tax:
sicore_taxes += tax
self.env["account.tax.repartition.line"].search(
sicore_tags = self.env["account.tax.repartition.line"].search(
[("tax_id", "in", sicore_taxes.ids), ("repartition_type", "=", "tax")]
).tag_ids = [Command.link(tag.id)]
)
sicore_tags_to_update = sicore_tags.filtered(lambda line: tag not in line.tag_ids)
sicore_tags_to_update.tag_ids = [Command.link(tag.id)]

# agregado de etiquetas para liquidacion de impuestos pago IIBB a cuenta (sifere web)
# consideramos de IIBB a todo lo que tiene 10n_ar_state_id
Expand All @@ -140,7 +147,9 @@ def _add_wh_taxes(self, company):
("tax_id.type_tax_use", "=", "none"),
("tax_id.l10n_ar_withholding_payment_type", "=", "customer"),
]
self.env["account.tax.repartition.line"].search(domain).tag_ids = [Command.link(tag.id)]
repartition_lines = self.env["account.tax.repartition.line"].search(domain)
if repartition_lines_without_tag := repartition_lines.filtered(lambda line: tag not in line.tag_ids):
repartition_lines_without_tag.tag_ids = [Command.link(tag.id)]

def _load(self, template_code, company, install_demo, force_create=True):
"""Luego de que creen los impuestos del archivo account.tax-ar_ri.csv de l10n_ar al instalar el plan de cuentas en la nueva compañìa argentina agregamos en este método las etiquetas que correspondan en los repartition lines."""
Expand Down
Loading