Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
11368 Lượt xem

Hello everyone,

I have a problem I am unable to fix on Odoo v12.

I have a many2one field related to "res.users" model, and need to show on this list, only the users that belongs to a specific group.

Searched for several related questions and none helped me to achieve what I need.

I have setup my groups as:
    - module_group_admin;
    - module_group_user; -----> I need to list these users
   
At this stage my groups/permissions are all working as expected.
The only problem I am having is that, when I access this many2one field, I see all users on the system and need to list ONLY the users from a specific and pre-selected group.

Can anyone help please?

Thank you in advance

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello Paulo,

This can be done by on-change function.

@api.multi
@api.onchange('company_id')
def onchange_company_id(self):
users = get the users from the both groups
return {'domain': {'your many2one field': [('id', 'in', users.ids)]}}

 I given this onchange based on company_id, every model having company field and it's having default value so i preferred  company_id field (you can do it with using another field also)


Ảnh đại diện
Huỷ bỏ
Tác giả

@Hilar and @subbarao, once again thank you very much for your clean explanation.

I have been learning a lot with both of you.

Câu trả lời hay nhất

Hi Paulo Matos,

This can be done in onchange function of many2one field. eg:

1. find the user ids in onchange of the many2one field.

users = self.env.ref('group_name').users.ids

2. return domain to the many2one field with these ids.

return {'domain': {'field_name': [('id', 'in', users)]}}

3. full function structure.

@api.onchange('many20ne_field_name')
def onchange_many2onefield(self):
"""

:param self:
:return:
"""
users = self.env.ref('group_name').users.ids
return {'domain': {'field_name': [('id', 'in', users)]}}

This logic can be used for onchange with other fields in the same model or do changes accordingly.


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 5 21
2956
1
thg 4 25
3629
2
thg 5 24
2243
0
thg 3 24
1374
3
thg 4 23
11731