[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) <jol@odoo.com>
This commit is contained in:
Ayushi Gorai
2024-02-07 09:18:55 +00:00
committed by Mahamadasif Ansari
parent d7fc43df58
commit de8c95c455
2 changed files with 18 additions and 0 deletions
+7
View File
@@ -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
+11
View File
@@ -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()