Restrict Contact Visibility by Company in Odoo 18
1/. Create User Group
Go to: Settings > Users & Companies > Groups
(or create a new group, e.g. "Strict Company Contacts Only")
Add the users in the "Users" tab.
2/. Add Security Record Rule for res.partner
Go to Settings > Technical > Security > Record Rules, and update or create a new rule for the res.partner
model.
-
Rule Name:
Multi-Company Contact Restriction
-
Model:
Contact (res.partner)
-
Domain Filter:
[('company_id', '=', user.company_id.id)]
-
Group Name: Select the group we just created in step 1. ( e.g. "Strict Company Contacts Only")
-
3/. Create New Automated Action:
-
Name:
Assign Company on Contact Creation
-
Model:
Contact
(res.partner
) -
Trigger:
On UI Change
-
When updating:
name
-
python code:
if not record.company_id:
record.write({'company_id': user.company_id.id})