Skip to Content
Menu
This question has been flagged
1 Reply
1658 Views

Odoo 15 to 17:


created a custom module, 

- inherit and added a field 'supervisor' in res.users

- inherit and added above field in user's form view


so, when add/edit a user, we can select another user as his Supervisor (like Manager in Employee)


requirement:

- in Contacts to create, write, delete a Supervisor can access his and all subordinates data only

- a User can see his data only


for CRM, i used below filter in Record Rule which is working fine now (please if possible, kindly advice if it has any mistake or if there is something to improve)

['|', '|',  ('user_id', '=', user.id), ('user_id', '=', False), ('user_id.user_ids.supervisor', '=', user.id)]


i tried it in Contact but it is showing all records to any logged-in user. please correct me to write a valid domain filter for Contact.


regards

Avatar
Discard
Best Answer

Hi,

In this context, all users are granted access because the condition includes 'user_id = False,'

Please change the conditions as follows,

['|',  ('user_id', '=', user.id), ('user_id.user_ids.supervisor', '=', user.id)],


In this domain, access to the record is granted to either the user or their supervisor.


For more details, refer to the blog:

https://www.cybrosys.com/blog/how-to-create-record-rule-in-odoo-16


Hope it helps

Avatar
Discard
Author

now it is not showing any record in Contacts with below error:

Uh-oh! Looks like you have stumbled upon some top-secret records.

Sorry, Manager-001 (id=22) doesn't have 'read' access to:
- Users, Manager-001 (res.users: 22)

remember, it was showing all records before the change you have mentioned.
regards

Related Posts Replies Views Activity
1
Apr 25
2613
1
Mar 25
2346
4
Aug 24
3787
1
Jan 24
3499
1
Jan 24
1674