[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) <jol@odoo.com>
This commit is contained in:
John Laterre (jol)
2023-02-23 14:54:14 +01:00
parent 63aaf17392
commit 987b82e5c9
+12 -5
View File
@@ -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):