From de8c95c455eb56bb221ec5406b2dd0e315af45b9 Mon Sep 17 00:00:00 2001 From: Ayushi Gorai Date: Sun, 6 Aug 2023 07:40:59 +0000 Subject: [PATCH] [FIX] account: handle error when incorrect domain is passed in account report When user gives wrong domain in any account report of report line and tries to access the same report similar error is generated. Steps to Produce: - Install 'Accounting' - Go to Accounting > Configuration > Accounting Reports - Open any account report and click on add a line - Now add a line in the report line - Create an expression select 'Computation Engine' as Odoo Domain. - In Formula add this domain [('code', '!=like', '620.%')] - And add Sub-Formula as 'sum' - Save the expression and also the report - Go to Reporting and select the above report Traceback will be generated ValueError: Invalid leaf ('code', '!=like', '620.%') When user applies invalid values in domain or invalid domain format it leads to the traceback because of this line: https://github.com/odoo/enterprise/blob/16.0/account_reports/models/account_report.py#L1510 sentry-4358342635 closes odoo/odoo#152910 X-original-commit: a41c9ef79a71230422eeb6c561f7f217c513bb30 Signed-off-by: John Laterre (jol) --- addons/account/i18n/account.pot | 7 +++++++ addons/account/models/account_report.py | 11 +++++++++++ 2 files changed, 18 insertions(+) diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index c5468b371b1..9f6ed9c24b1 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -7565,6 +7565,13 @@ msgstr "" msgid "Invalid \"Zip Range\", please configure it properly." msgstr "" +#. module: account +#. odoo-python +#: code:addons/account/models/account_report.py:0 +#, python-format +msgid "Invalid domain for expression '%s' of line '%s': %s" +msgstr "" + #. module: account #. odoo-python #: code:addons/account/models/company.py:0 diff --git a/addons/account/models/account_report.py b/addons/account/models/account_report.py index 71ec9618f97..d6bd290473b 100644 --- a/addons/account/models/account_report.py +++ b/addons/account/models/account_report.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import ast import re from collections import defaultdict @@ -549,6 +550,16 @@ class AccountReportExpression(models.Model): ), ] + @api.constrains('formula') + def _check_domain_formula(self): + for expression in self.filtered(lambda expr: expr.engine == 'domain'): + try: + domain = ast.literal_eval(expression.formula) + self.env['account.move.line']._where_calc(domain) + except: + raise UserError(_("Invalid domain for expression '%s' of line '%s': %s", + expression.label, expression.report_line_name, expression.formula)) + @api.depends('engine') def _compute_auditable(self): auditable_engines = self._get_auditable_engines()