From c36817262d78acb39dba6595cc5121c9edcf925e Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Fri, 28 Aug 2020 18:17:10 +0200 Subject: [PATCH] [FIX+IMP] account_financial_report: data can be None + no context mangling Depending on the calling method, data can be something different from a dictionary (like `None` if no keyword argument is provided), so this will crash. Example: mis_builder is crashing in its tests. We prevent that checking for a falsy value before trying to access the dictionary. We also avoid context mangling for non AFR reports (those without the key `account_financial_report_lang` in the dictionary), not callign to `with_context` in that case. --- account_financial_report/__manifest__.py | 2 +- .../models/ir_actions_report.py | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/account_financial_report/__manifest__.py b/account_financial_report/__manifest__.py index ea578d5a..06f57526 100644 --- a/account_financial_report/__manifest__.py +++ b/account_financial_report/__manifest__.py @@ -5,7 +5,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Account Financial Reports", - "version": "13.0.1.3.1", + "version": "13.0.1.3.2", "category": "Reporting", "summary": "OCA Financial Reports", "author": "Camptocamp SA," diff --git a/account_financial_report/models/ir_actions_report.py b/account_financial_report/models/ir_actions_report.py index 83c1435b..1c718526 100644 --- a/account_financial_report/models/ir_actions_report.py +++ b/account_financial_report/models/ir_actions_report.py @@ -9,19 +9,17 @@ class IrActionsReport(models.Model): @api.model def _prepare_account_financial_report_context(self, data): - lang = data.get("account_financial_report_lang") - return dict(self.env.context or {}, lang=lang) if lang else self.env.context + lang = data and data.get("account_financial_report_lang") or "" + return dict(self.env.context or {}, lang=lang) if lang else False @api.model def render_qweb_html(self, docids, data=None): - return super( - IrActionsReport, - self.with_context(self._prepare_account_financial_report_context(data)), - ).render_qweb_html(docids, data) + context = self._prepare_account_financial_report_context(data) + obj = self.with_context(context) if context else self + return super(IrActionsReport, obj).render_qweb_html(docids, data) @api.model def render_xlsx(self, docids, data): - return super( - IrActionsReport, - self.with_context(self._prepare_account_financial_report_context(data)), - ).render_xlsx(docids, data) + context = self._prepare_account_financial_report_context(data) + obj = self.with_context(context) if context else self + return super(IrActionsReport, obj).render_xlsx(docids, data)