[FIX] account: fix errors if formulas in reports are indented

Fixes parsing error that happened when formulas of reports contained indentation (white space, end of line, tabs).
The formula was then not computed correctly and an unclear error message was thrown.

closes odoo/odoo#105028

X-original-commit: 631c1292042083a566072462aa788c6fc410925a
Signed-off-by: Olivier Colson (oco) <oco@odoo.com>
This commit is contained in:
Claire Bretton (clbr)
2022-11-04 16:59:51 +01:00
parent 7a7497c48e
commit 7639990f93
+7 -2
View File
@@ -434,13 +434,16 @@ class AccountReportExpression(models.Model):
def _get_auditable_engines(self):
return {'tax_tags', 'domain', 'account_codes', 'external', 'aggregation'}
def _strip_formula(self, vals):
if 'formula' in vals and isinstance(vals['formula'], str):
vals['formula'] = re.sub(r'\s+', ' ', vals['formula'].strip())
@api.model_create_multi
def create(self, vals_list):
# Overridden so that we create the corresponding account.account.tag objects when instantiating an expression
# with engine 'tax_tags'.
for vals in vals_list:
if 'formula' in vals and isinstance(vals['formula'], str):
vals['formula'] = vals['formula'].replace('\n', '').strip()
self._strip_formula(vals)
result = super().create(vals_list)
@@ -460,6 +463,8 @@ class AccountReportExpression(models.Model):
if 'formula' not in vals:
return super().write(vals)
self._strip_formula(vals)
tax_tags_expressions = self.filtered(lambda x: x.engine == 'tax_tags')
former_formulas_by_country = defaultdict(lambda: [])
for expr in tax_tags_expressions: