Browse Source

[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.
pull/749/head
Pedro M. Baeza 4 years ago
committed by João Marques
parent
commit
c36817262d
  1. 2
      account_financial_report/__manifest__.py
  2. 18
      account_financial_report/models/ir_actions_report.py

2
account_financial_report/__manifest__.py

@ -5,7 +5,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
"name": "Account Financial Reports", "name": "Account Financial Reports",
"version": "13.0.1.3.1",
"version": "13.0.1.3.2",
"category": "Reporting", "category": "Reporting",
"summary": "OCA Financial Reports", "summary": "OCA Financial Reports",
"author": "Camptocamp SA," "author": "Camptocamp SA,"

18
account_financial_report/models/ir_actions_report.py

@ -9,19 +9,17 @@ class IrActionsReport(models.Model):
@api.model @api.model
def _prepare_account_financial_report_context(self, data): 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 @api.model
def render_qweb_html(self, docids, data=None): 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 @api.model
def render_xlsx(self, docids, data): 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)
Loading…
Cancel
Save