Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1742 Vistas

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
Descartar
Mejor respuesta

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
Descartar
Autor

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

Publicaciones relacionadas Respuestas Vistas Actividad
1
abr 25
2737
1
mar 25
2452
4
ago 24
3897
1
ene 24
3587
1
ene 24
1715