[FIX] base,core: order of self.env.companies

Using a `frozenset` leads to non deterministic issues.
Because when nothing is set in the context key `allowed_company_ids`,
`self.env.companies` will fallback on `self['res.company'].browse(user_company_ids)`
Since the browsing is done on a non ordered set, the recordset doesn't
follow the `_order` set on the model, by definition.

This has the effect of not being deterministic when iterating on
`self.env.companies`.

For instance
https://runbot.odoo.com/runbot/build/20539598

closes odoo/odoo#104538

X-original-commit: bfee55b14c918c44ebbb2563d5dc0e102edf396e
Signed-off-by: Rémy Voet <ryv@odoo.com>
Signed-off-by: William André (wan) <wan@odoo.com>
This commit is contained in:
william
2022-10-28 20:39:50 +02:00
committed by william-andre
parent f8b60ea4cb
commit bebfa9b52c
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -622,7 +622,7 @@ class Environment(Mapping):
if company_ids:
if not self.su:
user_company_ids = self.user._get_company_ids()
if any(cid not in user_company_ids for cid in company_ids):
if set(company_ids) - set(user_company_ids):
raise AccessError(_("Access to unauthorized or invalid companies."))
return self['res.company'].browse(company_ids[0])
return self.user.company_id.with_env(self)
@@ -652,7 +652,7 @@ class Environment(Mapping):
user_company_ids = self.user._get_company_ids()
if company_ids:
if not self.su:
if any(cid not in user_company_ids for cid in company_ids):
if set(company_ids) - set(user_company_ids):
raise AccessError(_("Access to unauthorized or invalid companies."))
return self['res.company'].browse(company_ids)
# By setting the default companies to all user companies instead of the main one