From 97a239a325f7ed7cba43c9f56d7aed597a30b236 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Tue, 10 Jan 2023 18:14:03 +0100 Subject: [PATCH] [IMP] account_financial_report: Trial balance changes: - Show Initial balance and Ending balance only when it is necessary with currency + hide currency column - Show currency in the correct column - Create a dict with all keys when it does not exist - Prevent wrong values TT41158 --- .../report/templates/trial_balance.xml | 37 ++----- .../report/trial_balance.py | 100 +++++++----------- .../report/trial_balance_xlsx.py | 18 +--- 3 files changed, 52 insertions(+), 103 deletions(-) diff --git a/account_financial_report/report/templates/trial_balance.xml b/account_financial_report/report/templates/trial_balance.xml index 6a3e6cbb..dcb18c82 100644 --- a/account_financial_report/report/templates/trial_balance.xml +++ b/account_financial_report/report/templates/trial_balance.xml @@ -178,17 +178,11 @@
Ending balance
- -
Cur.
-
- Initial - balance cur. -
-
- Ending balance - cur. -
+
Initial + balance cur.
+
Ending balance + cur.
@@ -572,10 +566,6 @@ - -
- -
@@ -609,12 +600,6 @@ - -
- -
@@ -650,6 +636,7 @@ @@ -683,6 +670,7 @@ @@ -694,7 +682,6 @@
-
@@ -703,14 +690,12 @@
-
-
@@ -889,12 +874,10 @@ />
- -
-
+
-
+
diff --git a/account_financial_report/report/trial_balance.py b/account_financial_report/report/trial_balance.py index cfd08942..68f4ee56 100644 --- a/account_financial_report/report/trial_balance.py +++ b/account_financial_report/report/trial_balance.py @@ -211,33 +211,15 @@ class TrialBalanceReport(models.AbstractModel): ): for tb in tb_period_acc: acc_id = tb["account_id"][0] - total_amount[acc_id] = {} + total_amount[acc_id] = self._prepare_total_amount(tb, foreign_currency) total_amount[acc_id]["credit"] = tb["credit"] total_amount[acc_id]["debit"] = tb["debit"] total_amount[acc_id]["balance"] = tb["balance"] total_amount[acc_id]["initial_balance"] = 0.0 - total_amount[acc_id]["ending_balance"] = tb["balance"] - if foreign_currency: - total_amount[acc_id]["initial_currency_balance"] = 0.0 - total_amount[acc_id]["ending_currency_balance"] = round( - tb["amount_currency"], 2 - ) for tb in tb_initial_acc: acc_id = tb["account_id"] if acc_id not in total_amount.keys(): - total_amount[acc_id] = {} - total_amount[acc_id]["credit"] = 0.0 - total_amount[acc_id]["debit"] = 0.0 - total_amount[acc_id]["balance"] = 0.0 - total_amount[acc_id]["initial_balance"] = tb["balance"] - total_amount[acc_id]["ending_balance"] = tb["balance"] - if foreign_currency: - total_amount[acc_id]["initial_currency_balance"] = round( - tb["amount_currency"], 2 - ) - total_amount[acc_id]["ending_currency_balance"] = round( - tb["amount_currency"], 2 - ) + total_amount[acc_id] = self._prepare_total_amount(tb, foreign_currency) else: total_amount[acc_id]["initial_balance"] = tb["balance"] total_amount[acc_id]["ending_balance"] += tb["balance"] @@ -250,23 +232,42 @@ class TrialBalanceReport(models.AbstractModel): ) return total_amount + @api.model + def _prepare_total_amount(self, tb, foreign_currency): + res = { + "credit": 0.0, + "debit": 0.0, + "balance": 0.0, + "initial_balance": tb["balance"], + "ending_balance": tb["balance"], + } + if foreign_currency: + res["initial_currency_balance"] = round(tb["amount_currency"], 2) + res["ending_currency_balance"] = round(tb["amount_currency"], 2) + return res + @api.model def _compute_acc_prt_amount( self, total_amount, tb, acc_id, prt_id, foreign_currency ): - total_amount[acc_id][prt_id] = {} - total_amount[acc_id][prt_id]["credit"] = 0.0 - total_amount[acc_id][prt_id]["debit"] = 0.0 - total_amount[acc_id][prt_id]["balance"] = 0.0 - total_amount[acc_id][prt_id]["initial_balance"] = tb["balance"] - total_amount[acc_id][prt_id]["ending_balance"] = tb["balance"] - if foreign_currency: - total_amount[acc_id][prt_id]["initial_currency_balance"] = round( - tb["amount_currency"], 2 - ) - total_amount[acc_id][prt_id]["ending_currency_balance"] = round( - tb["amount_currency"], 2 + # Add keys to dict if not exists + if acc_id not in total_amount: + total_amount[acc_id] = self._prepare_total_amount(tb, foreign_currency) + if prt_id not in total_amount[acc_id]: + total_amount[acc_id][prt_id] = self._prepare_total_amount( + tb, foreign_currency ) + else: + # Increase balance field values + total_amount[acc_id][prt_id]["initial_balance"] = tb["balance"] + total_amount[acc_id][prt_id]["ending_balance"] += tb["balance"] + if foreign_currency: + total_amount[acc_id][prt_id]["initial_currency_balance"] = round( + tb["amount_currency"], 2 + ) + total_amount[acc_id][prt_id]["ending_currency_balance"] += round( + tb["amount_currency"], 2 + ) return total_amount @api.model @@ -283,18 +284,14 @@ class TrialBalanceReport(models.AbstractModel): partners_data.update( {prt_id: {"id": prt_id, "name": tb["partner_id"][1]}} ) - total_amount[acc_id][prt_id] = {} + total_amount[acc_id][prt_id] = self._prepare_total_amount( + tb, foreign_currency + ) total_amount[acc_id][prt_id]["credit"] = tb["credit"] total_amount[acc_id][prt_id]["debit"] = tb["debit"] total_amount[acc_id][prt_id]["balance"] = tb["balance"] total_amount[acc_id][prt_id]["initial_balance"] = 0.0 - total_amount[acc_id][prt_id]["ending_balance"] = tb["balance"] - if foreign_currency: - total_amount[acc_id][prt_id]["initial_currency_balance"] = 0.0 - total_amount[acc_id][prt_id]["ending_currency_balance"] = round( - tb["amount_currency"], 2 - ) - partners_ids.add(tb["partner_id"]) + partners_ids.add(tb["partner_id"]) for tb in tb_initial_prt: acc_id = tb["account_id"][0] if tb["partner_id"]: @@ -303,26 +300,9 @@ class TrialBalanceReport(models.AbstractModel): partners_data.update( {prt_id: {"id": prt_id, "name": tb["partner_id"][1]}} ) - if acc_id not in total_amount.keys(): - total_amount = self._compute_acc_prt_amount( - total_amount, tb, acc_id, prt_id, foreign_currency - ) - partners_ids.add(tb["partner_id"]) - elif prt_id not in total_amount[acc_id].keys(): - total_amount = self._compute_acc_prt_amount( - total_amount, tb, acc_id, prt_id, foreign_currency - ) - partners_ids.add(tb["partner_id"]) - else: - total_amount[acc_id][prt_id]["initial_balance"] += tb["balance"] - total_amount[acc_id][prt_id]["ending_balance"] += tb["balance"] - if foreign_currency: - total_amount[acc_id][prt_id][ - "initial_currency_balance" - ] += round(tb["amount_currency"], 2) - total_amount[acc_id][prt_id][ - "ending_currency_balance" - ] += round(tb["amount_currency"], 2) + total_amount = self._compute_acc_prt_amount( + total_amount, tb, acc_id, prt_id, foreign_currency + ) return total_amount, partners_data def _remove_accounts_at_cero(self, total_amount, show_partner_details, company): diff --git a/account_financial_report/report/trial_balance_xlsx.py b/account_financial_report/report/trial_balance_xlsx.py index a15427e4..68a871c0 100644 --- a/account_financial_report/report/trial_balance_xlsx.py +++ b/account_financial_report/report/trial_balance_xlsx.py @@ -60,19 +60,12 @@ class TrialBalanceXslx(models.AbstractModel): if report.foreign_currency: foreign_currency = { 7: { - "header": _("Cur."), - "field": "currency_id", - "field_currency_balance": "currency_id", - "type": "many2one", - "width": 7, - }, - 8: { "header": _("Initial balance"), "field": "initial_currency_balance", "type": "amount_currency", "width": 14, }, - 9: { + 8: { "header": _("Ending balance"), "field": "ending_currency_balance", "type": "amount_currency", @@ -118,19 +111,12 @@ class TrialBalanceXslx(models.AbstractModel): if report.foreign_currency: foreign_currency = { 6: { - "header": _("Cur."), - "field": "currency_id", - "field_currency_balance": "currency_id", - "type": "many2one", - "width": 7, - }, - 7: { "header": _("Initial balance"), "field": "initial_currency_balance", "type": "amount_currency", "width": 14, }, - 8: { + 7: { "header": _("Ending balance"), "field": "ending_currency_balance", "type": "amount_currency",