From 0a4b989536be518cb1f4e8211f5a2b56791dfe5b Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Tue, 31 Mar 2020 14:22:13 +0000 Subject: [PATCH] [FIX] base: default check_company domain. The supported case of check_company on `res_company` model fields was not considered when specifying a default domain on `check_company=True` fields. closes odoo/odoo#48674 Nb: It is already correctly supported in the `_check_company()` method. Signed-off-by: Raphael Collet (rco) --- odoo/fields.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/odoo/fields.py b/odoo/fields.py index a958695b618..89064379bcb 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -2395,11 +2395,14 @@ class _Relational(Field): else: return "[('company_id', 'in', [allowed_company_ids[0], False])]" else: + # when using check_company=True on a field on 'res.company', the + # company_id comes from the id of the current record + cid = "id" if self.model_name == "res.company" else "company_id" if self.comodel_name == "res.users": # User allowed company ids = user.company_ids - return "['|', (not company_id, '=', True), ('company_ids', 'in', [company_id])]" + return f"['|', (not {cid}, '=', True), ('company_ids', 'in', [{cid}])]" else: - return "[('company_id', 'in', [company_id, False])]" + return f"[('company_id', 'in', [{cid}, False])]" return self.domain(env[self.model_name]) if callable(self.domain) else self.domain def null(self, record):