[FIX] analytic: constraint should only apply on current recordset

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) <wan@odoo.com>
This commit is contained in:
Thibault Francois
2023-03-18 03:32:55 +01:00
parent b0211e91a7
commit 47c06171e4
+2 -1
View File
@@ -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."))