跳至內容
選單
此問題已被標幟
2 回覆
5829 瀏覽次數

Hello guys.

I want a Many2many field that get all the users that belongs to a specific group. I have something like this but is not working, can you help me please?


managers = fields.Many2many('res.users', string="Users in charge",
default=lambda self: self.env.ref("custom_module.group_pos").id)
頭像
捨棄
最佳答案

Hi 21m,

Please try this code:

managers = fields.Many2many(
'res.users', string="Users in charge",
default=lambda self: self.env.ref("custom_module.group_pos").users.ids)

Please vote the answer if it helps you.

Thanks

頭像
捨棄
最佳答案
def _default_res_users(self):
    users_obj = self.env['res.users']
users = []
for user in users_obj.search([]):
if user.has_group("custom_module.group_pos"):
         users.append(user.id)
return users
managers = fields.Many2many('res.users', string="Users in charge",
default=_default_res_users)

Try This.

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
4月 24
1359
1
5月 23
4094
2
7月 22
4693
3
12月 21
4502
5
9月 23
49384