From 7639990f93a522b90eeef01c166506b393885bed Mon Sep 17 00:00:00 2001 From: "Claire Bretton (clbr)" Date: Thu, 3 Nov 2022 09:53:39 +0000 Subject: [PATCH] [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) --- addons/account/models/account_report.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_report.py b/addons/account/models/account_report.py index ca3716ebbb0..c73a76be768 100644 --- a/addons/account/models/account_report.py +++ b/addons/account/models/account_report.py @@ -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: