Reputation: 560
I have 3 fields which in my module page.2 are for product categories and 1 for product. The categories fields consist of different categories. Now I want to add filter so that what ever category I set in the field, only those product should list in the products field . It is a type of sorting or filtering. I dont have much idea of using filter in such a scenerio under form view. Here is my code.py:
class deg_form(osv.osv):
_name = "deg.form"
_columns = {
'categ1':fields.many2one('product.category','Parent Category'),
'categ2':fields.many2one('product.category','Child Category'),
'my_products':fields.many2one('product.product','Products',size=64),
}
deg_form()
and here is its xml:
<record id="mywin_form_view" model="ir.ui.view">
<field name="name">mywin.form</field>
<field name="model">deg.form</field>
<field eval="7" name="priority"/>
<field name="arch" type="xml">
<form string="FORM DATA" version="7.0">
<h1>
<label for="categ1" string="Parent category"/>
<field name="categ1" />
</h1>
<h1>
<label for="categ2" string="Child category"/>
<field name="categ2" />
</h1>
<newline/>
<h1>
<label for="my_products" string="Products" domain = "[('categ1','=',True)]"/>
<field name="my_products"/>
</h1>
<button name="show_product" string="SHOW PRODUCT" type="action"/>
</form>
</field>
</record>
please help me fix this
Upvotes: 0
Views: 559
Reputation: 800
Use domain filter in py or xml as
domain = "[('categ_id','=',categ1)]"
Or
Overwrite def search method of product.product and pass categ field as parameter
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
if context is None:
context = {}
if context and context.get('search_default_categ_id', False):
args.append((('categ_id', '=', context['categ_id'])))
return super(product_product, self).search(cr, uid, args, offset=offset, limit=limit, order=order, context=context,count=count)
For Parent child relation of product category use this domain filter in py or xml (categ2)
domain = "[('parent_id','=',categ1)]"
Upvotes: 2