Hi Sehrish, Kabeer thanks for the tips, although I think I´m getting closer, I still can´t make it work, I went coding with method 2 (Sehrish) using it inside a computed field but several exceptions have been occurring:
field:
'make_invisible':fields.function(get_user, string="Is Invisible", readonly=0)
XML:
<field name="make_invisible"/>
First try:
def get_user(self, cr, uid, ids, name, arg, context=None):
_logger.debug("This is GET_USER method ")
desired_group_name = self.env['res.groups'].search([('name','=','GM')])
is_desired_group = self.env.user.id in desired_group_name.users.ids
self.make_visible=is_desired_group
got:
desired_group_name = self.env['res.groups'].search([('name','=','GM')])
AttributeError: 'hr.employee' object has no attribute 'env'
Second try: (try to use api.multi to avoid previous error)
@api.multi
def get_user(self, cr, uid, ids, name, arg, context=None):
_logger.debug("This is GET_USER method ")
desired_group_name = self.env['res.groups'].search([('name','=','GM')])
is_desired_group = self.env.user.id in desired_group_name.users.ids
self.make_visible=is_desired_group
got:
File "/opt/odoo/openerp/api.py", line 363, in old_api
result = method(recs, *args, **kwargs)
TypeError: get_user() takes at least 6 arguments (4 given)
Third try: (use different function definition with api.multi)
@api.multi
def get_user(self):
_logger.debug("This is GET_USER method ")
desired_group_name = self.env['res.groups'].search([('name','=','GM')])
is_desired_group = self.env.user.id in desired_group_name.users.ids
self.make_visible=is_desired_group
got:
File "/opt/odoo/openerp/api.py", line 709, in __new__
self.cr, self.uid, self.context = self.args = (cr, uid, frozendict(context))
ValueError: dictionary update sequence element #0 has length 1; 2 is required
Fouth try: (tried to use original function definition with pool.get instead of env)
def get_user(self, cr, uid, ids, name, arg, context=None):
_logger.debug("This is GET_USER method ")
#desired_group_name = self.env['res.groups'].search([('name','=','GM')])
desired_group_name = self.pool.get('res.groups').search([('name','=','GM')])
is_desired_group = self.env.user.id in desired_group_name.users.ids
self.make_visible=is_desired_group
got:
File "/opt/odoo/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
TypeError: search() takes at least 4 arguments (2 given)
Please help, dont know what else to do and what am I doing wrong!!!
Define your function like this
` def get_user (self, cr, uid, ids, name, arg, context=None):
//statement