Skip to content

Commit

Permalink
Merge PR #3926 into 17.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Jan 17, 2025
2 parents 7e0c926 + d23efdd commit 0c2403a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 9 deletions.
9 changes: 9 additions & 0 deletions l10n_es_aeat/models/l10n_es_aeat_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,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
6 changes: 1 addition & 5 deletions l10n_es_aeat/models/l10n_es_aeat_tax_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
20 changes: 17 additions & 3 deletions l10n_es_vat_book/models/l10n_es_vat_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion l10n_es_vat_book/models/l10n_es_vat_book_line_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
14 changes: 14 additions & 0 deletions l10n_es_vat_book/models/l10n_es_vat_book_tax_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 17 additions & 0 deletions l10n_es_vat_book/views/l10n_es_vat_book_tax_summary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,25 @@
<tree decoration-muted="special_tax_group">
<field name="special_tax_group" />
<field name="base_amount" />
<!-- We don't add a visibility condition, as that would mean to have
a field determining if there are moves or not, which can drain the
performance -->
<button
name="view_move_lines_base"
type="object"
aria-label="Show journal items"
title="Show journal items"
icon="fa-search-plus"
/>
<field name="tax_id" />
<field name="tax_amount" />
<button
name="view_move_lines_tax"
type="object"
aria-label="Show journal items"
title="Show journal items"
icon="fa-search-plus"
/>
<field name="total_amount" />
</tree>
</field>
Expand Down

0 comments on commit 0c2403a

Please sign in to comment.