如何在表单上提交过多个过滤器?

时间:2014-05-08 06:40:04

标签: python openerp openerp-7

我的模块第2页中有3个字段用于产品类别,1个用于产品。类别字段由不同的类别组成。现在我想添加过滤器,以便我在字段中设置的类别,只有那些产品应该在产品字段中列出。它是一种排序或过滤。我不太了解在表单视图下的这样的场景中使用过滤器。这是我的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()

,这是它的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>

请帮我解决这个问题

1 个答案:

答案 0 :(得分:2)

使用py或xml中的域过滤器作为

domain = "[('categ_id','=',categ1)]"

覆盖product.product的def搜索方法并将categories字段作为参数传递

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)

对于产品类别的父子关系,请在py或xml中使用此域过滤器 (categ2)

domain = "[('parent_id','=',categ1)]"