问题描述:
HR 模块中,员工离职后,由HR将员工信息中的"active"字段选为"False",隐藏相应的员工信息。
结果确实隐藏掉了相应成员信息,但是通过odoo中的 Advanced Search 高级搜索,还是可以通过active==False,来搜索出离职人员的信息。
解决方案:
首先Advanced Search的list中是默认有对应table的所有字段的,所以隐藏掉active即可。
def fields_get(self, cr, uid, fields=None, context=None, write_access=True):
fields_to_hide = ['active']
res = super(model_name, self).fields_get(cr, uid, fields, context)
for field in fields_to_hide:
res[field]['selectable'] = False
return res
重写一下fields_get函数,将字段的selectable属性变为False,这样会对所有组隐藏该字段。
可以为指定的组,开放active,在该函数中添加组的限制即可。
def fields_get(self, cr, uid, fields=None, context=None, write_access=True):
fields_to_hide = ['active']
res = super(model_name, self).fields_get(cr, uid, fields, context)
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
if not (user.has_group('base.group_erp_manager') or
user.has_group('group_name_1') or
user.has_group('group_name_2')):
for field in fields_to_hide:
res[field]['selectable'] = False
return res
这样在base.group_erp_manager、group_name_1、group_name_2组中的用户,仍然可以通过active来搜索离职人员信息。
注释:
selectable属性如果直接拿到字段定义的位置加,不报错,但没作用。
还有一个解决方案:
将该table在security的.csv文件中加的权限为0,0,0,0,然后在记录级别的权限控制中加权限。