How to filter many2one res.parner field in odoo

2019-07-17 22:11发布

I have

x_trainer_id = fields.Many2one('res.partner', string='Trainer')

field, and I want to filter data in it by the value that is put in category_id tag field in partner form.

I want to show just those records in it their category_id tag value is defined Trainer.

2条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-17 22:25

If i understand this correct, try to define you field in your view like:

<field name="x_trainer_id" domain="[('category_id','=',category_id[0][2])]" />

The field category_id has to be defined in that view, too. But if you extend the res.partner views, there shouldn't be any problem.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-07-17 22:28

try this way in python:

x_trainer_id = fields.Many2one(comodel_name='res.partner', string='Trainer',domain=lambda self: [('category_id.name', '=', 'Trainer')])

pass domain=lambda self: [('category_id.name', '=', 'Trainer')]

查看更多
登录 后发表回答