Skip to content

Commit

Permalink
[FIX] core: include inactive companies in _check_company
Browse files Browse the repository at this point in the history
`res.users.company_ids` returns only active companies, while
`res.users.company_id` may be inactive. This leads to a situation where
`self.env.company` is inactive but still associated to `self.env.user`.

Since in multiple cases the default value for relational fields pointing
to `res.users` is `self.env.user`, we may get an error in this check:
`self.env.company` is not in `self.env.user.company_ids`.

See https://github.com/odoo/odoo/blob/5506ca7/odoo/addons/base/models/res_users.py#L281-L282

closes odoo#147127

Signed-off-by: Raphael Collet <rco@odoo.com>
  • Loading branch information
aj-fuentes committed Jan 8, 2024
1 parent d507be4 commit 4b09663
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions odoo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4035,7 +4035,7 @@ def _check_company(self, fnames=None):
corecord = record.sudo()[name]
if corecord:
domain = corecord._check_company_domain(company)
if domain and not corecord.filtered_domain(domain):
if domain and not corecord.with_context(active_test=False).filtered_domain(domain):
inconsistencies.append((record, name, corecord))
# The second part of the check (for property / company-dependent fields) verifies that the records
# linked via those relation fields are compatible with the company that owns the property value, i.e.
Expand All @@ -4046,7 +4046,7 @@ def _check_company(self, fnames=None):
corecord = record.sudo()[name]
if corecord:
domain = corecord._check_company_domain(company)
if domain and not corecord.filtered_domain(domain):
if domain and not corecord.with_context(active_test=False).filtered_domain(domain):
inconsistencies.append((record, name, corecord))

if inconsistencies:
Expand Down

0 comments on commit 4b09663

Please sign in to comment.