Filter in openerp [closed]

妖精的绣舞 提交于 2019-12-12 04:39:57

问题


How to filter many2one field in openerp.

_columns = {
   'hello': fields.selection([('1','one'),('2','two')],'hello'),
   'product_id': fields.many2one('product.product',
                                 'Product',
                                 domain=[('type','=',hello)])'
   ...
}

If assume product.product have field called type which is also selection and its value same as hello does it work in xml or python??


回答1:


you can try the domain attribute of fields.many2one as below

'product_id': fields.many2one('product.product', 'Product', domain=[('purchase_ok','=',True)], change_default=True),

alternative way -> you can provide domain in your XML View as below,

<field name="product_id" domain="[('purchase_ok','=',True)]"/>




回答2:


You need to specify the domain in the view file which you want the many to one field to be filtered. For e.g. if you want to filter suppliers from the customers list just give the following in the view.

:domain="[('supplier','=',True)]"



回答3:


Try the context or domain parameters described in the developer book. I haven't used them, but you can probably find examples in the core modules. The best description of domain syntax is on the orm.search() method.




回答4:


I think u want to filter product.product according to hello fields right. so write the onchange method on hello filed in xml and in method, filter the product id which type is match to hello filed value.

In function/method u can add all the ids which type is matches to hello filed value, in the list and after return this list to product_id.



来源:https://stackoverflow.com/questions/5150859/filter-in-openerp

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