How to filter many2one res.parner field in odoo

南笙酒味 提交于 2019-12-14 03:56:54

问题


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.


回答1:


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.




回答2:


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')]



来源:https://stackoverflow.com/questions/37598262/how-to-filter-many2one-res-parner-field-in-odoo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!