From a394558c368b5dfa4be177a8801fcf360b3fb897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Thu, 27 Apr 2023 09:07:26 +0200 Subject: [PATCH 1/2] [FIX] account_financial_report: Prevent error related to currency from General ledger Use case: Generate report (showing foreign currency) with accounts with defined currency. Traceback: File "/odoo/odoo-server/odoo/addons/base/models/ir_qweb_fields.py", line 448, in value_to_html fmt = "%.{0}f".format(display_currency.decimal_places) AttributeError: 'int' object has no attribute 'decimal_places' The above exception was the direct cause of the following exception: Error to render compiling AST AttributeError: 'int' object has no attribute 'decimal_places' Template: account_financial_report.report_general_ledger_lines Path: /t/div/div[2]/t[6]/t[1]/div[1]/t[1]/span/t Node: TT42804 --- .../report/templates/general_ledger.xml | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/account_financial_report/report/templates/general_ledger.xml b/account_financial_report/report/templates/general_ledger.xml index fb8f2d31..08d0190c 100644 --- a/account_financial_report/report/templates/general_ledger.xml +++ b/account_financial_report/report/templates/general_ledger.xml @@ -313,6 +313,10 @@ +
@@ -332,7 +336,7 @@ > @@ -345,7 +349,7 @@ > @@ -356,7 +360,7 @@ > @@ -693,6 +697,10 @@ +
@@ -704,7 +712,7 @@ > @@ -719,7 +727,7 @@ > @@ -736,7 +744,7 @@ > @@ -751,7 +759,7 @@ > From 2bb7251e0b0823e18c59ff3763afd56904c84bc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Tue, 9 May 2023 10:15:26 +0200 Subject: [PATCH 2/2] [FIX] account_financial_report: Prevent error related to currency from General ledger Use case: Generate xlsx report (showing foreign currency) with accounts with defined currency. Traceback: File "/opt/odoo/auto/addons/account_financial_report/report/abstract_report_xlsx.py", line 535, in _get_currency_amt_format field_name = "{}_{}".format(field_prefix, currency.name) AttributeError: 'int' object has no attribute 'name' --- .../report/abstract_report_xlsx.py | 5 ++++- .../report/general_ledger_xlsx.py | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/account_financial_report/report/abstract_report_xlsx.py b/account_financial_report/report/abstract_report_xlsx.py index fedecb9c..4c0cbe70 100644 --- a/account_financial_report/report/abstract_report_xlsx.py +++ b/account_financial_report/report/abstract_report_xlsx.py @@ -531,7 +531,10 @@ class AbstractReportXslx(models.AbstractModel): format_amt = report_data["formats"]["format_amount"] field_prefix = "format_amount" if "currency_id" in line_object and line_object.get("currency_id", False): - currency = line_object["currency_id"] + if isinstance(line_object["currency_id"], int): + currency = self.env["res.currency"].browse(line_object["currency_id"]) + else: + currency = line_object["currency_id"] field_name = "{}_{}".format(field_prefix, currency.name) if hasattr(self, field_name): format_amt = getattr(self, field_name) diff --git a/account_financial_report/report/general_ledger_xlsx.py b/account_financial_report/report/general_ledger_xlsx.py index 44eb091e..7dce837d 100644 --- a/account_financial_report/report/general_ledger_xlsx.py +++ b/account_financial_report/report/general_ledger_xlsx.py @@ -236,6 +236,15 @@ class GeneralLedgerXslx(models.AbstractModel): # Display array header for move lines self.write_array_header(report_data) + account.update( + { + "currency_id": accounts_data[account["id"]]["currency_id"], + "currency_name": accounts_data[account["id"]][ + "currency_name" + ], + } + ) + # Display initial balance line for partner group_item.update( { @@ -247,6 +256,9 @@ class GeneralLedgerXslx(models.AbstractModel): if "grouped_by" in account else "", "currency_id": accounts_data[account["id"]]["currency_id"], + "currency_name": accounts_data[account["id"]][ + "currency_name" + ], } ) if foreign_currency: @@ -304,8 +316,6 @@ class GeneralLedgerXslx(models.AbstractModel): group_item.update( { "final_bal_curr": group_item["fin_bal"]["bal_curr"], - "currency_name": group_item["currency_id"].name, - "currency_id": group_item["currency_id"].id, } ) self.write_ending_balance_from_dict(group_item, report_data) @@ -325,8 +335,6 @@ class GeneralLedgerXslx(models.AbstractModel): account.update( { "final_bal_curr": account["fin_bal"]["bal_curr"], - "currency_name": account["currency_id"].name, - "currency_id": account["currency_id"].id, } ) self.write_ending_balance_from_dict(account, report_data)