跳至内容
菜单
此问题已终结
4 回复
9077 查看

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.

形象
丢弃

use domain filter for the field

最佳答案

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

形象
丢弃
编写者 最佳答案

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?

形象
丢弃
相关帖文 回复 查看 活动
0
7月 25
273
0
4月 25
747
2
2月 25
5833
1
12月 24
1404
1
7月 24
2193