From 07893e0e77096cb1880d7ca9943507a2ed090361 Mon Sep 17 00:00:00 2001 From: dhx Date: Fri, 5 Apr 2024 19:58:38 +0200 Subject: [PATCH] [FIX] account_financial_report: fix the order of vat tag report lines - 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) --- account_financial_report/report/vat_report.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/account_financial_report/report/vat_report.py b/account_financial_report/report/vat_report.py index dc1cbd8923e..1dec3d6f74f 100644 --- a/account_financial_report/report/vat_report.py +++ b/account_financial_report/report/vat_report.py @@ -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] + 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): @@ -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"] = []