Odoo Advanced Search 隐藏相应字段

问题描述:

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,然后在记录级别的权限控制中加权限。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值