From 987b82e5c9add1e9e2a9fdabe6dc73a3a6daa9ec Mon Sep 17 00:00:00 2001 From: "John Laterre (jol)" Date: Tue, 21 Feb 2023 10:35:48 +0000 Subject: [PATCH] [FIX] account: add a unique constraint on report line expressions Currently, when editing a report line, it's possible to create a new expression with a label already used on the same report line. This is problematic as the columns are using the expression label to select the right expression. Indeed, one expression is going to be selected but there isn't any obvious way to guess which one. The solution is to add an SQL constraint on the report line expression. task-3199014 closes odoo/odoo#113222 Signed-off-by: John Laterre (jol) --- addons/account/models/account_report.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/addons/account/models/account_report.py b/addons/account/models/account_report.py index 9562fcb0651..506aeb29b13 100644 --- a/addons/account/models/account_report.py +++ b/addons/account/models/account_report.py @@ -448,11 +448,18 @@ class AccountReportExpression(models.Model): " in case the carryover destination requires more complex logic." ) - _sql_constraints = [( - "domain_engine_subformula_required", - "CHECK(engine != 'domain' OR subformula IS NOT NULL)", - "Expressions using 'domain' engine should all have a subformula." - )] + _sql_constraints = [ + ( + "domain_engine_subformula_required", + "CHECK(engine != 'domain' OR subformula IS NOT NULL)", + "Expressions using 'domain' engine should all have a subformula." + ), + ( + "line_label_uniq", + "UNIQUE(report_line_id,label)", + "The expression label must be unique per report line." + ), + ] @api.depends('engine') def _compute_auditable(self):