Skip to content

Commit

Permalink
[FIX] account_financial_report: fix the order of vat tag report lines
Browse files Browse the repository at this point in the history
- Currently the lines of the vat tax tag report are not properly sorted
  leading to similar tags (only differing by their sign) ending up far
  apart making it difficult to see when values have to be subtracted
  from another to get the final result.
- This patch sorts the lines first by the code (currently always empty)
  second by the name of the tag (without the sign) and only third by
  the sign (to always have the '+' in front of the '-' tag)
  • Loading branch information
dhx committed Jan 5, 2025
1 parent 8e6d9de commit 07893e0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions account_financial_report/report/vat_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ def _get_tags_data(self, tags_ids):
tags = self.env["account.account.tag"].browse(tags_ids)
tags_data = {}
for tag in tags:
tags_data.update({tag.id: {"code": "", "name": tag.name}})
sign = ""
name = tag.name
if tag.name[0] in ("+", "-"):
name = tag.name[1:]
sign = tag.name[0]

Check warning on line 161 in account_financial_report/report/vat_report.py

View check run for this annotation

Codecov / codecov/patch

account_financial_report/report/vat_report.py#L160-L161

Added lines #L160 - L161 were not covered by tests
tags_data.update({tag.id: {"code": "", "name": name, "sign": sign}})
return tags_data

def _get_vat_report_tag_data(self, vat_report_data, tax_data, tax_detail):
Expand Down Expand Up @@ -185,8 +190,10 @@ def _get_vat_report_tag_data(self, vat_report_data, tax_data, tax_detail):
vat_report[tag_id]["tax"] += tax_move_line["tax"]
tags_data = self._get_tags_data(vat_report.keys())
vat_report_list = []
for tag_id in vat_report.keys():
vat_report[tag_id]["name"] = tags_data[tag_id]["name"]
for tag_id in sorted(
vat_report.keys(), key=lambda t: "{code}{name}{sign}".format(**tags_data[t])
):
vat_report[tag_id]["name"] = "{sign}{name}".format(**tags_data[tag_id])
vat_report[tag_id]["code"] = tags_data[tag_id]["code"]
if tax_detail:
vat_report[tag_id]["taxes"] = []
Expand Down

0 comments on commit 07893e0

Please sign in to comment.