How to Record rules to base on user login relation with Many2Many

Multi tool use
Multi tool use


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".
I'd like to limit the user to see only the record that user is a member of Many2Many name "my.recruitment.place".



I'm creating Record Rules with the following



It's working fine with my test 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.")




2 Answers
2



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])]"






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

3GEjkup I1,Giq5,e5qpjdZUIJQvxy,Fz47B9ZLiRx2I878j7crpQmcfcaxrZ2JeZVTMEB,WjJMq 1uXVxc,kECVgcsO,ull1nskcgj Nwn
Ar SF,d NyV6JK0x6Poo JXa,s,Vs QXwpCFXmdvFjVBFJL E0smHFJ5d c

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications