From a3281058b080478451611b0c377fea243faf4cd8 Mon Sep 17 00:00:00 2001 From: svs-odoo Date: Tue, 24 Sep 2019 09:17:17 +0000 Subject: [PATCH] [FIX] models: check_company on res.users field Before this commit, when a record of a model who has a `res.users` field it could fail the `check_company` because the check looks for `company_id` who is the default company of the user. In the case of `res.users`, `check_company` must look after the `company_ids` of the user. --- odoo/models.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/odoo/models.py b/odoo/models.py index 564882bd88c..3efb5d6f598 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -3076,7 +3076,12 @@ Fields: # The first part of the check verifies that all records linked via relation fields are compatible # with the company of the origin document, i.e. `self.account_id.company_id == self.company_id` for name in regular_fields: - if not (record[name].company_id <= company): + # Special case with `res.users` since an user can belong to multiple companies. + if record[name]._name == 'res.users' and record[name].company_ids: + if not (company <= record[name].company_ids): + inconsistent_fields.add(name) + inconsistent_recs |= record + elif not (record[name].company_id <= company): inconsistent_fields.add(name) inconsistent_recs |= record # The second part of the check (for property / company-dependent fields) verifies that the records @@ -3088,7 +3093,12 @@ Fields: else: company = self.env.company for name in property_fields: - if not (record[name].company_id <= company): + # Special case with `res.users` since an user can belong to multiple companies. + if record[name]._name == 'res.users' and record[name].company_ids: + if not (company <= record[name].company_ids): + inconsistent_fields.add(name) + inconsistent_recs |= record + elif not (record[name].company_id <= company): inconsistent_fields.add(name) inconsistent_recs |= record