Skip to content

Commit

Permalink
Merge PR #723 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 Dec 10, 2024
2 parents e37042c + a4d6a89 commit 1dcacf2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
27 changes: 26 additions & 1 deletion account_analytic_tag/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from odoo import fields, models
# Copyright 2024 Tecnativa - Pedro M. Baeza
from odoo import api, fields, models
from odoo.tools import frozendict


class AccountMoveLine(models.Model):
Expand All @@ -9,6 +11,29 @@ class AccountMoveLine(models.Model):
string="Analytic Tags",
)

@api.depends("analytic_tag_ids")
def _compute_all_tax(self):
# Include the analytic tags in the tax move line when applicable
res = None
for line in self:
res = super(AccountMoveLine, line)._compute_all_tax()
new_compute_all_tax = {}
for tax_key, tax_vals in line.compute_all_tax.items():
tax = (
self.env["account.tax.repartition.line"]
.browse(tax_key.get("tax_repartition_line_id", False))
.tax_id
)
if tax.analytic:
new_key = tax_key.copy()
new_key["analytic_tag_ids"] = [
(6, 0, [x.id for x in line.analytic_tag_ids])
]
tax_key = frozendict(new_key)
new_compute_all_tax[tax_key] = tax_vals
line.compute_all_tax = new_compute_all_tax
return res

def _prepare_analytic_lines(self):
"""Set tags to the records that have the same or no analytical account."""
vals = super()._prepare_analytic_lines()
Expand Down
14 changes: 14 additions & 0 deletions account_analytic_tag/tests/test_account_analytic_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,17 @@ def test_action_post_analytic_lines_05(self):
self.assertNotIn(
self.account_analytic_tag_b, self.line_a.analytic_line_ids.tag_ids
)

def test_analytic_tags_in_tax(self):
tax = self.env["account.tax"].create(
{
"name": "account_analytic_tag tax example",
"amount_type": "percent",
"type_tax_use": "sale",
"amount": 10,
"analytic": True,
}
)
self.line_a.tax_ids = [(4, tax.id)]
tax_line = self.invoice.line_ids.filtered(lambda x, t=tax: x.tax_line_id == t)
self.assertEqual(self.account_analytic_tag_a, tax_line.analytic_tag_ids)

0 comments on commit 1dcacf2

Please sign in to comment.