Search code examples
ormxml-rpcodoo

How can I check if a user is Manager for a specific module in Odoo?


I am looking for a way to check if a logged-in user is Manager for a particular Module like 'Point of sale'. Using SQL I am able to check this condition, but can we accomplish the same using ORM?

Following is my sql query which is listing the users who are Managers for 'Point of sale' module: Looking for an equivalent of the same in ORM OR some other way to accomplish the desired thing:

select login, usr.id as user_id, grp.id group_id, grp.name, cat.name 
from res_users usr, res_groups_users_rel rel, res_groups grp, ir_module_category cat
where usr.id = rel.uid
and rel.gid = grp.id
and grp.category_id = cat.id
and cat.name = 'Point of Sale'
and grp.name = 'Manager'; 

Solution

  • And finally it's done : ) Following is my working code in python:

    models.execute_kw(db, uid, password,
        'res.users', 'search',[[['id','=',userid],['groups_id.name','=','Manager'],['groups_id.category_id.name','=','Point of Sale']]],{})