Friday, 27 October 2017

How to check login user group in odoo

    In this post you will learn how to check login user group. The need of this post is, to sometime we need to visible invisible some filed on the basis of login user group or we want to perform some action on the basis of login user. To do so we need to get login user group. There are two ways

to get login user group. We can use these lines of code on a "button click, onchange, computed filed etc".

    Method 1:
    user = self.env['res.users'].sudo().search(
    desired_group_user = self.env['res.groups'].sudo().search( 
    query = "select gid from res_groups_users_rel where 
       gid ={} and uid={}".format(,
    is_desired_group =
    desired_user_gr = self.env['res.groups'].sudo().search(
Method 2:
    desired_group_name = self.env['res.groups'].search(
    is_desired_group = in desired_group_name.users.ids