Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2 Respostas
11345 Visualizações

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

Avatar
Cancelar
Melhor resposta

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)


Avatar
Cancelar
Autor

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

I have been learning a lot with both of you.

Melhor resposta

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.


Avatar
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
0
mai. 21
2954
1
abr. 25
3610
2
mai. 24
2216
0
mar. 24
1355
3
abr. 23
11707