Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

Record rules to restrict employee subordinate hierarchy view

By
Mudi Vand
on 1/6/15, 3:42 AM 1,529 views

I want to set some record rules to restrict employees to view only their profile and their subordinates profiles. No one else out of a particular employee's subordinate hierarchy should be displayed to him. For example, this is my employee hierarchy.

  • Alex
    • Benjamin
      • David
      • Edward
        • Ivan
        • Jack
      • Frank
    • Charles
      • George
      • Henry

When Alex logged in, he should be able to see all the employees. When Benjamin logged in, he should be able to see his profile and David's, Edward's, Frank's, Ivan's and Jack's profiles only. When David logged in, he should be able to see his profile only.

I have tried the following record rules on Employee object:

  1. [('user_id','=',user.id)] Allows to see logged in user's profile only.
  2. [('parent_id.user_id','=',user.id)] Allows to see immediate subordinates only. That means, when Alex logged in, he can see Benjamin and Charles only, not the in depth hierarchy.
  3. [('child_ids','child_of', [user.id])] It gives a view of logged in user, his first immediate subordinate, first next level subordinate. That means, when Alex logged in, he can see his profile, Benjamin's profile and David's profile only.

I still couldn't work out a way to satisfy my requirement. Any help would be appreciated.

Thank you very much!

Thank you very very much Bruno! It really worked! Just the way I wanted. Thank you!

Mudi Vand
on 1/6/15, 6:07 AM
2
Bruno PLANCHER
On 1/6/15, 5:58 AM

Hello Mudi Vand,

Your problem is that you try to apply a child_of on res.users model (which have not parent hierarchy, as long as i know).

Have you tried to use ONLY this rule: 

[('id', 'child_of', [employee.id for employee in user.employee_ids])]

With that, i think it will filter the Employees using the employee "profile" of the current user. The child_of will be applied to the hr.employee model (which have parent_id field, the default field to be used by child_of operator).

Does it work ?

Regards

0
Faris
On 2/9/16, 8:55 AM

Where I should apply the obove rule

I mean witch group of users

Regards, 

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/6/15, 3:42 AM
Seen: 1529 times
Last updated: 2/9/16, 8:55 AM