Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
4 Odpowiedzi
9078 Widoki

I have created a model which one field is "Many2one" type, and its co-model is "res.users":

to_approve_by = fields.Many2one(comodel_name='res.users', string='To Approve by')

On the form view for this model. I want the selection widget of this field only list the 'res.users' in one certain group, such as "Project / Manager".

So, how to editor the code to realize it?

Are there someone give me a sample code or some advice?

Thanks.

Awatar
Odrzuć

use domain filter for the field

Najlepsza odpowiedź

Hi,

try something like this (not tested) :

def _get_users_group_project(self):
    return [('id', 'in', self.env.ref('xml_id_of_group').users.ids)]

to_approve_by = fields.Many2one('res.users', string='To Approve by', domain=lambda self:self._get_users_group_project())

Regards

Awatar
Odrzuć
Autor Najlepsza odpowiedź

Dear Mohammed Amal,

Did your means that I should code my .py file like below?:

to_approve_by = fields.Many2one(comodel_name='res.users',
string='To Approve by',
domain="[('groups_id.ids','??',??)]")

But I don't know how to code the 'operator' and 'value' section in the tuple. So, Would your please give me a sample?

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
lip 25
276
0
kwi 25
751
2
lut 25
5837
1
gru 24
1405
1
lip 24
2194