From ae79dda47c21744e08f59a6c8ffeae8f9e11ed15 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Thu, 16 Jan 2025 17:39:27 +0100 Subject: [PATCH] [IMP] l10n_es_vat_book + l10n_es_aeat: Drill through on tax summary Allow to drill through in the tax summary to list journal items that leads to the base and tax amounts. As we are on this, there's a tool method now in base module l10n_es_aeat for opening this kind of view, and fixing that the journal items was always open with move grouping by default. TT52996 --- l10n_es_aeat/models/l10n_es_aeat_report.py | 9 +++++++++ l10n_es_aeat/models/l10n_es_aeat_tax_line.py | 6 +----- l10n_es_vat_book/models/l10n_es_vat_book.py | 20 ++++++++++++++++--- .../models/l10n_es_vat_book_line_tax.py | 6 +++++- .../models/l10n_es_vat_book_tax_summary.py | 14 +++++++++++++ .../views/l10n_es_vat_book_tax_summary.xml | 17 ++++++++++++++++ 6 files changed, 63 insertions(+), 9 deletions(-) diff --git a/l10n_es_aeat/models/l10n_es_aeat_report.py b/l10n_es_aeat/models/l10n_es_aeat_report.py index 1231a3e7f7a..8c3950ad687 100644 --- a/l10n_es_aeat/models/l10n_es_aeat_report.py +++ b/l10n_es_aeat/models/l10n_es_aeat_report.py @@ -533,3 +533,12 @@ def get_html(self): rcontext ) return result + + @api.model + def _view_move_lines(self, amls): + res = self.env.ref("account.action_account_moves_all_a").sudo().read()[0] + view = self.env.ref("l10n_es_aeat.view_move_line_tree") + res["context"] = {"create": 0} + res["views"] = [(view.id, "tree")] + res["domain"] = [("id", "in", amls.ids)] + return res diff --git a/l10n_es_aeat/models/l10n_es_aeat_tax_line.py b/l10n_es_aeat/models/l10n_es_aeat_tax_line.py index a68ebe700d8..4d6bc1f5b30 100644 --- a/l10n_es_aeat/models/l10n_es_aeat_tax_line.py +++ b/l10n_es_aeat/models/l10n_es_aeat_tax_line.py @@ -34,8 +34,4 @@ class L10nEsAeatTaxLine(models.Model): model = fields.Char(index=True, readonly=True, required=True, string="Model name") def get_calculated_move_lines(self): - res = self.env.ref("account.action_account_moves_all_a").sudo().read()[0] - view = self.env.ref("l10n_es_aeat.view_move_line_tree") - res["views"] = [(view.id, "tree")] - res["domain"] = [("id", "in", self.move_line_ids.ids)] - return res + return self.env["l10n.es.aeat.report"]._view_move_lines(self.move_line_ids) diff --git a/l10n_es_vat_book/models/l10n_es_vat_book.py b/l10n_es_vat_book/models/l10n_es_vat_book.py index 00bf7f4f2e2..c22a4994670 100644 --- a/l10n_es_vat_book/models/l10n_es_vat_book.py +++ b/l10n_es_vat_book/models/l10n_es_vat_book.py @@ -150,6 +150,8 @@ def _prepare_vat_book_tax_summary(self, tax_lines, book_type): "tax_id": tax_line.tax_id.id, "vat_book_id": self.id, "special_tax_group": tax_line.special_tax_group, + "base_move_line_ids": tax_line.base_move_line_ids.ids, + "move_line_ids": tax_line.move_line_ids.ids, } tax_summary_data_recs[tax_line.tax_id][ "base_amount" @@ -158,6 +160,12 @@ def _prepare_vat_book_tax_summary(self, tax_lines, book_type): tax_summary_data_recs[tax_line.tax_id][ "total_amount" ] += tax_line.total_amount + tax_summary_data_recs[tax_line.tax_id][ + "base_move_line_ids" + ] += tax_line.base_move_line_ids.ids + tax_summary_data_recs[tax_line.tax_id][ + "move_line_ids" + ] += tax_line.move_line_ids.ids return tax_summary_data_recs @api.model @@ -249,13 +257,19 @@ def _prepare_book_line_tax_vals(self, move_line, vat_book_line): balance if move_line.tax_ids and not move_line.tax_line_id else 0.0 ) fee_amount_untaxed = balance if move_line.tax_line_id else 0.0 - return { + vals = { "tax_id": move_line.tax_line_id.id, "base_amount": base_amount_untaxed, "tax_amount": fee_amount_untaxed, - "move_line_ids": [(4, move_line.id)], + "base_move_line_ids": [], + "move_line_ids": [], "special_tax_group": False, } + if move_line.tax_ids: + vals["base_move_line_ids"].append((4, move_line.id)) + elif move_line.tax_line_id: + vals["move_line_ids"].append((4, move_line.id)) + return vals def upsert_book_line_tax(self, move_line, vat_book_line, implied_taxes): vals = self._prepare_book_line_tax_vals(move_line, vat_book_line) @@ -279,7 +293,7 @@ def upsert_book_line_tax(self, move_line, vat_book_line, implied_taxes): tax_lines[key]["tax_id"] = tax.id else: tax_lines[key]["base_amount"] += vals["base_amount"] - tax_lines[key]["move_line_ids"] += vals["move_line_ids"] + tax_lines[key]["base_move_line_ids"] += vals["base_move_line_ids"] # For later matching special taxes tax_lines[key]["other_tax_ids"] = (move_line.tax_ids - tax).ids diff --git a/l10n_es_vat_book/models/l10n_es_vat_book_line_tax.py b/l10n_es_vat_book/models/l10n_es_vat_book_line_tax.py index 6d5587c8742..7aaa87e9698 100644 --- a/l10n_es_vat_book/models/l10n_es_vat_book_line_tax.py +++ b/l10n_es_vat_book/models/l10n_es_vat_book_line_tax.py @@ -30,7 +30,11 @@ class L10nEsVatBookLineTax(models.Model): compute="_compute_total_amount", store=True, ) - + base_move_line_ids = fields.Many2many( + comodel_name="account.move.line", + string="Move Lines (Base)", + relation="account_move_line_l10n_es_vat_book_line_tax_base_rel", + ) move_line_ids = fields.Many2many( comodel_name="account.move.line", string="Move Lines" ) diff --git a/l10n_es_vat_book/models/l10n_es_vat_book_tax_summary.py b/l10n_es_vat_book/models/l10n_es_vat_book_tax_summary.py index d1769eca1fe..23f44352854 100644 --- a/l10n_es_vat_book/models/l10n_es_vat_book_tax_summary.py +++ b/l10n_es_vat_book/models/l10n_es_vat_book_tax_summary.py @@ -20,3 +20,17 @@ class L10nEsVatBookIssuedTaxSummary(models.Model): required=True, ondelete="cascade", ) + base_move_line_ids = fields.Many2many( + comodel_name="account.move.line", + string="Journal items (Base)", + relation="account_move_line_l10n_es_vat_book_tax_summary_base_rel", + ) + move_line_ids = fields.Many2many( + comodel_name="account.move.line", string="Journal items" + ) + + def view_move_lines_base(self): + return self.env["l10n.es.aeat.report"]._view_move_lines(self.base_move_line_ids) + + def view_move_lines_tax(self): + return self.env["l10n.es.aeat.report"]._view_move_lines(self.move_line_ids) diff --git a/l10n_es_vat_book/views/l10n_es_vat_book_tax_summary.xml b/l10n_es_vat_book/views/l10n_es_vat_book_tax_summary.xml index cdf1f4be4e4..df9bc6efdbd 100644 --- a/l10n_es_vat_book/views/l10n_es_vat_book_tax_summary.xml +++ b/l10n_es_vat_book/views/l10n_es_vat_book_tax_summary.xml @@ -24,8 +24,25 @@ + +