From 47c06171e44b127cd41c41e2359f442ed6844d71 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Fri, 17 Mar 2023 12:52:11 +0000 Subject: [PATCH] [FIX] analytic: constraint should only apply on current recordset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this commit, if a single analytic line in the database has an inconsistent company with it's anlytic account, all creation of an analytic account was impossible because the constraint _check_company_consistency is checked on the entire table. This commit restrict the _check_company_consistency only on the current record set. closes odoo/odoo#115768 X-original-commit: 49bf7d149095e0c202cc53171a99eea8ec5b59b7 Signed-off-by: William André (wan) --- addons/analytic/models/analytic_account.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/analytic/models/analytic_account.py b/addons/analytic/models/analytic_account.py index f28cc6fbb8c..b97caae1b79 100644 --- a/addons/analytic/models/analytic_account.py +++ b/addons/analytic/models/analytic_account.py @@ -108,7 +108,8 @@ class AccountAnalyticAccount(models.Model): FROM account_analytic_line line JOIN account_analytic_account account ON line.account_id = account.id WHERE line.company_id != account.company_id and account.company_id IS NOT NULL - ''') + AND account.id IN %s + ''', [tuple(self.ids)]) if self._cr.fetchone(): raise UserError(_("You can't set a different company on your analytic account since there are some analytic items linked to it."))