how can i use function value in Domain filter

断了今生、忘了曾经 提交于 2020-01-06 15:25:16

问题


I am getting current login user id by following function

    def _get_user_name(self, cr, uid, *args):
    user_obj = self.pool.get('res.users')
    user_value = user_obj.browse(cr, uid, uid)
    return user_value.id or False

and now i want to use its value in this field's Domain like ....

    x_trainer_id = fields.Many2one('res.partner', string='Trainer',domain=[('user_id.id','=','get_user_name')])

How is it possible? I'll be very thankful....


回答1:


you can do it as below:

x_trainer_id = fields.Many2one('res.partner', string='Trainer',domain=lambda self: [('id', '=', self.env.uid)])

pass domain=lambda self: [('id', '=', self.env.uid)]



来源:https://stackoverflow.com/questions/37618187/how-can-i-use-function-value-in-domain-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!