Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] l10n_es_aeat_mod190: Multiple fixes #3828

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 2 additions & 7 deletions l10n_es_aeat_mod190/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,12 @@ def _compute_is_aeat_perception_subkey_visible(self):
)
)

@api.depends("move_id.aeat_perception_key_id")
@api.depends("move_id.aeat_perception_key_id", "move_id.aeat_perception_subkey_id")
def _compute_aeat_perception_keys(self):
for line in self:
aeat_perception_key_id = False
aeat_perception_subkey_id = False
if (
line.move_id.is_invoice()
and line.display_type == "product"
Copy link
Member

Choose a reason for hiding this comment

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

Esta línea no hay que quitarla.

Copy link
Member Author

Choose a reason for hiding this comment

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

Si que hay que quitarla. No se muestran las lineas de impuestos

Copy link
Member

Choose a reason for hiding this comment

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

Vale, pero entonces lo que hay es que cambiar la condición. Lo que no se debe computar es para las secciones, notas, etc. Hay que mirar también qué pasa con el resto de líneas, como COGS, anticipos, payment terms, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

De hecho, en general el approach yo lo quitaría. Si por ejemplo introduzco nóminas, debería ponerse en la clave B,pero esta parte del código lo bloquea todo 😭

Mi siguerencia seria dejarlo como (not line.move_id.is_invoice() or line.display_type in ["product","tax"])

Copy link
Member

Choose a reason for hiding this comment

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

Sí, pues a eso me refería.

and line.id in line.move_id.invoice_line_ids.ids
and line.move_id.aeat_perception_key_id
):
if line.move_id.is_invoice() and line.move_id.aeat_perception_key_id:
aeat_perception_key_id = line.move_id.aeat_perception_key_id.id
aeat_perception_subkey_id = line.move_id.aeat_perception_subkey_id.id
line.update(
Expand Down
98 changes: 68 additions & 30 deletions l10n_es_aeat_mod190/models/l10n_es_aeat_mod190_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,129 +545,149 @@
# Calculo campos SIN incapacidad
@api.depends("report_id", "report_id.tax_line_ids", "discapacidad")
def _compute_percepciones_dinerarias(self):
for item in self.filtered(
lambda x: not x.discapacidad or x.discapacidad == "0"
):
for item in self:
if item.discapacidad and item.discapacidad != "0":
item.percepciones_dinerarias = 0.0
Copy link
Member

Choose a reason for hiding this comment

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

En lugar de esto, se puede hacer al principio de todo un self.percepciones_dinerarias = 0

continue

Check warning on line 551 in l10n_es_aeat_mod190/models/l10n_es_aeat_mod190_report.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_aeat_mod190/models/l10n_es_aeat_mod190_report.py#L550-L551

Added lines #L550 - L551 were not covered by tests
tax_lines = item.report_id.tax_line_ids.filtered(
lambda x: x.field_number in (11, 15) and x.res_id == item.report_id.id
)
value = 0.0
for move_line in tax_lines.move_line_ids:
for move_line in tax_lines.move_line_ids.filtered(item._check_lines):
Copy link
Member

Choose a reason for hiding this comment

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

Esto debería llevar lambda, y además estar en el objeto donde self sea el elemento.

Copy link
Member Author

Choose a reason for hiding this comment

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

En todos lados se usa el mismo filtro que encima es grande. Lo he pasado al final

Copy link
Member

Choose a reason for hiding this comment

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

Sí, pero yo te digo de la forma en la que se debería implementar. Mira también lo del tema de rendimiento.

value += move_line.debit - move_line.credit
item.percepciones_dinerarias = value

@api.depends("report_id", "report_id.tax_line_ids", "discapacidad")
def _compute_retenciones_dinerarias(self):
for item in self.filtered(
lambda x: not x.discapacidad or x.discapacidad == "0"
):
for item in self:
if item.discapacidad and item.discapacidad != "0":
item.retenciones_dinerarias = 0.0
continue

Check warning on line 565 in l10n_es_aeat_mod190/models/l10n_es_aeat_mod190_report.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_aeat_mod190/models/l10n_es_aeat_mod190_report.py#L564-L565

Added lines #L564 - L565 were not covered by tests
tax_lines = item.report_id.tax_line_ids.filtered(
lambda x: x.field_number in (12, 16) and x.res_id == item.report_id.id
)
value = 0.0
for move_line in tax_lines.move_line_ids:
for move_line in tax_lines.move_line_ids.filtered(item._check_lines):
value += move_line.credit - move_line.debit
item.retenciones_dinerarias = value

@api.depends("report_id", "report_id.tax_line_ids", "discapacidad")
def _compute_percepciones_en_especie(self):
for item in self.filtered(
lambda x: not x.discapacidad or x.discapacidad == "0"
):
for item in self:
if item.discapacidad and item.discapacidad != "0":
item.percepciones_en_especie = 0.0
continue

Check warning on line 579 in l10n_es_aeat_mod190/models/l10n_es_aeat_mod190_report.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_aeat_mod190/models/l10n_es_aeat_mod190_report.py#L578-L579

Added lines #L578 - L579 were not covered by tests
tax_lines = item.report_id.tax_line_ids.filtered(
lambda x: x.field_number == 13 and x.res_id == item.report_id.id
)
pde = rde = 0.0
for move_line in tax_lines.move_line_ids:
for move_line in tax_lines.move_line_ids.filtered(item._check_lines):
pde += move_line.debit - move_line.credit
rde += move_line.credit - move_line.debit
item.percepciones_en_especie = pde - rde

@api.depends("report_id", "report_id.tax_line_ids", "discapacidad")
def _compute_ingresos_a_cuenta_efectuados(self):
for item in self.filtered(
lambda x: not x.discapacidad or x.discapacidad == "0"
):
for item in self:
if item.discapacidad and item.discapacidad != "0":
item.ingresos_a_cuenta_efectuados = 0.0
continue

Check warning on line 594 in l10n_es_aeat_mod190/models/l10n_es_aeat_mod190_report.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_aeat_mod190/models/l10n_es_aeat_mod190_report.py#L593-L594

Added lines #L593 - L594 were not covered by tests
tax_lines = item.report_id.tax_line_ids.filtered(
lambda x: x.field_number == 13 and x.res_id == item.report_id.id
)
value = 0.0
for move_line in tax_lines.move_line_ids:
for move_line in tax_lines.move_line_ids.filtered(item._check_lines):
value += move_line.debit - move_line.credit
item.ingresos_a_cuenta_efectuados = value

@api.depends("report_id", "report_id.tax_line_ids", "discapacidad")
def _compute_ingresos_a_cuenta_repercutidos(self):
for item in self.filtered(
lambda x: not x.discapacidad or x.discapacidad == "0"
):
for item in self:
if item.discapacidad and item.discapacidad != "0":
item.ingresos_a_cuenta_repercutidos = 0.0
continue

Check warning on line 608 in l10n_es_aeat_mod190/models/l10n_es_aeat_mod190_report.py

View check run for this annotation

Codecov / codecov/patch

l10n_es_aeat_mod190/models/l10n_es_aeat_mod190_report.py#L607-L608

Added lines #L607 - L608 were not covered by tests
tax_lines = item.report_id.tax_line_ids.filtered(
lambda x: x.field_number == 13 and x.res_id == item.report_id.id
)
value = 0.0
for move_line in tax_lines.move_line_ids:
for move_line in tax_lines.move_line_ids.filtered(item._check_lines):
value += move_line.credit - move_line.debit
item.ingresos_a_cuenta_repercutidos = value

# Calculo campos CON incapacidad
@api.depends("report_id", "report_id.tax_line_ids", "discapacidad")
def _compute_percepciones_dinerarias_incap(self):
"""La misma lógica que para percepciones_dinerarias."""
for item in self.filtered(lambda x: x.discapacidad or x.discapacidad != "0"):
for item in self:
if not item.discapacidad or item.discapacidad == "0":
item.percepciones_dinerarias_incap = 0.0
continue
tax_lines = item.report_id.tax_line_ids.filtered(
lambda x: x.field_number in (11, 15) and x.res_id == item.report_id.id
)
value = 0.0
for move_line in tax_lines.move_line_ids:
for move_line in tax_lines.move_line_ids.filtered(item._check_lines):
value += move_line.debit - move_line.credit
item.percepciones_dinerarias_incap = value

@api.depends("report_id", "report_id.tax_line_ids", "discapacidad")
def _compute_retenciones_dinerarias_incap(self):
"""La misma lógica que para retenciones_dinerarias."""
for item in self.filtered(lambda x: x.discapacidad or x.discapacidad != "0"):
for item in self:
if not item.discapacidad or item.discapacidad == "0":
item.retenciones_dinerarias_incap = 0.0
continue
tax_lines = item.report_id.tax_line_ids.filtered(
lambda x: x.field_number in (12, 16) and x.res_id == item.report_id.id
)
value = 0.0
for move_line in tax_lines.move_line_ids:
for move_line in tax_lines.move_line_ids.filtered(item._check_lines):
value += move_line.credit - move_line.debit
item.retenciones_dinerarias_incap = value

@api.depends("report_id", "report_id.tax_line_ids", "discapacidad")
def _compute_percepciones_en_especie_incap(self):
"""La misma lógica que para percepciones_en_especie."""
for item in self.filtered(lambda x: x.discapacidad or x.discapacidad != "0"):
for item in self:
if not item.discapacidad or item.discapacidad == "0":
item.percepciones_en_especie_incap = 0.0
continue
tax_lines = item.report_id.tax_line_ids.filtered(
lambda x: x.field_number == 13 and x.res_id == item.report_id.id
)
pde = rde = 0.0
for move_line in tax_lines.move_line_ids:
for move_line in tax_lines.move_line_ids.filtered(item._check_lines):
pde += move_line.debit - move_line.credit
rde += move_line.credit - move_line.debit
item.percepciones_en_especie_incap = pde - rde

@api.depends("report_id", "report_id.tax_line_ids", "discapacidad")
def _compute_ingresos_a_cuenta_efectuados_incap(self):
"""La misma lógica que para ingresos_a_cuenta_efectuados."""
for item in self.filtered(lambda x: x.discapacidad or x.discapacidad != "0"):
for item in self:
if not item.discapacidad or item.discapacidad == "0":
item.ingresos_a_cuenta_efectuados_incap = 0.0
continue
tax_lines = item.report_id.tax_line_ids.filtered(
lambda x: x.field_number == 13 and x.res_id == item.report_id.id
)
value = 0.0
for move_line in tax_lines.move_line_ids:
for move_line in tax_lines.move_line_ids.filtered(item._check_lines):
value += move_line.debit - move_line.credit
item.ingresos_a_cuenta_efectuados_incap = value

@api.depends("report_id", "report_id.tax_line_ids", "discapacidad")
def _compute_ingresos_a_cuenta_repercutidos_incap(self):
"""La misma lógica que para ingresos_a_cuenta_repercutidos."""
for item in self.filtered(lambda x: x.discapacidad or x.discapacidad != "0"):
for item in self:
if not item.discapacidad or item.discapacidad == "0":
item.ingresos_a_cuenta_repercutidos_incap = 0.0
continue
tax_lines = item.report_id.tax_line_ids.filtered(
lambda x: x.field_number == 13 and x.res_id == item.report_id.id
)
value = 0.0
for move_line in tax_lines.move_line_ids:
for move_line in tax_lines.move_line_ids.filtered(item._check_lines):
value += move_line.credit - move_line.debit
item.ingresos_a_cuenta_repercutidos_incap = value

Expand All @@ -686,3 +706,21 @@
def onchange_aeat_perception_key_id(self):
if self.aeat_perception_key_id:
self.aeat_perception_subkey_id = False

def _check_lines(self, line):
return (
line.partner_id == self.partner_id
and (
(line.aeat_perception_key_id or line.partner_id.aeat_perception_key_id)
== self.aeat_perception_key_id
)
and (
(line.aeat_perception_subkey_id)
or (
not line.aeat_perception_key_id
and line.partner_id.aeat_perception_subkey_id
)
or self.env["l10n.es.aeat.report.perception.subkey"]
)
== self.aeat_perception_subkey_id
)
Loading