diff --git a/l10n_es_aeat_mod190/models/account_move_line.py b/l10n_es_aeat_mod190/models/account_move_line.py index cba577d42f5..dcf836dfbe7 100644 --- a/l10n_es_aeat_mod190/models/account_move_line.py +++ b/l10n_es_aeat_mod190/models/account_move_line.py @@ -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" - 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( diff --git a/l10n_es_aeat_mod190/models/l10n_es_aeat_mod190_report.py b/l10n_es_aeat_mod190/models/l10n_es_aeat_mod190_report.py index c2f0b8d6ac1..bcd7fcde2a7 100644 --- a/l10n_es_aeat_mod190/models/l10n_es_aeat_mod190_report.py +++ b/l10n_es_aeat_mod190/models/l10n_es_aeat_mod190_report.py @@ -545,67 +545,72 @@ def _compute_partner_id_ad_required(self): # 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 + 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 = 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 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 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 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 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 @@ -613,36 +618,45 @@ def _compute_ingresos_a_cuenta_repercutidos(self): @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 @@ -650,24 +664,30 @@ def _compute_percepciones_en_especie_incap(self): @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 @@ -686,3 +706,21 @@ def onchange_partner_id(self): 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 + )