[英]How to Record rules to base on user login relation with Many2Many
I'm trying to develop my knowledge. 我正在努力发展我的知识。 Then I make a personal project name "My Recruitment".
然后,我将个人项目命名为“我的招聘”。 I've inherited model "hr.applicant" and add new field name "x_place".
我继承了模型“ hr.applicant”,并添加了新的字段名称“ x_place”。 I'd like to limit the user to see only the record that user is a member of Many2Many name "my.recruitment.place".
我想限制用户仅查看该用户是Many2Many成员“ my.recruitment.place”的记录。
I'm creating Record Rules with the following 我正在使用以下内容创建记录规则
It's working fine with my test ir.rule 我的测试ir.rule工作正常
['|',('x_place','in',[1,2,3,4]),('x_place','=',False)]
but I expect the result 但我期望结果
xxx = self.env['my.recruitment.place'].search([('res_users_id','=',user.id)])
['|',('x_place','in',[xxx]),('x_place','=',False)]
Here is my class: 这是我的课:
class MYRecruitment(models.Model):
_inherit = ['hr.applicant']
x_place = fields.Many2one('my.recruitment.place', "Place")
class MyRecruitmentPlace(models.Model):
_name = "my.recruitment.place"
_description = "Place of Recruitment"
_sql_constraints = [
('name_uniq', 'unique (name)', 'The name of the place of Recruitment must be unique!')
]
name = fields.Char("Place", required=True, translate=True)
user_ids = fields.Many2many('res.users', string="Owners")
sequence = fields.Integer("Sequence", default=1, help="Gives the sequence order when displaying a list of place.")
Try this: 尝试这个:
['|',('x_place','in',xxx.ids),('x_place','=',False)]
Hope it will help you. 希望对您有帮助。
Model: 模型:
@api.multi
def _place_get(self):
return self.search([])
Rule Definition (Domain Filter): 规则定义(域过滤器):
['|',('user_id', '=', user.id),('x_place','in',[_place_get.ids])]
Error: 错误:
ValueError: <class 'NameError'>: "name '_place_get' is not defined" while evaluating
"['|',('user_id', '=', user.id),('x_place','in',[_place_get.ids])]"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.