2015-09-08 48 views
3

我創建了一個自定義的odoo模塊,現在我想創建一個搜索過濾器,可以很容易地同時搜索多個字段。我將這段代碼添加到了我的xml中,我可以單獨搜索每個字段,但希望將它們分組爲一個字符串,以便用戶可以使用一次搜索來搜索所有字段(製造商名稱1-6)。有誰知道這是否可能?如何在Odoo中用一個字符串搜索多個自定義字段?

<record id="product_template_search_custom_view" model="ir.ui.view"> 
    <field name="name">product.template.customsearch</field> 
    <field name="model">product.template</field> 
    <field name="inherit_id" ref="product.product_template_search_view"/> 
    <field name="arch" type="xml"> 
     <xpath expr="/search/field[@name='name']" position="before"> 
      <field name="x_mfrname1" string="Mfr Name1"/> 
      <field name="x_mfrname2" string="Mfr Name2"/> 
      <field name="x_mfrname3" string="Mfr Name3"/> 
      <field name="x_mfrname4" string="Mfr Name4"/> 
      <field name="x_mfrname5" string="Mfr Name5"/> 
      <field name="x_mfrname6" string="Mfr Name6"/> 
     </xpath> 
    </field> 
</record> 

回答

4

可以使用filter_domain屬性

<record id="product_template_search_custom_view" model="ir.ui.view"> 
    <field name="name">product.template.customsearch</field> 
    <field name="model">product.template</field> 
    <field name="inherit_id" ref="product.product_template_search_view"/> 
    <field name="arch" type="xml"> 
     <field name="name" position="replace"> 
      <field name="name" filter_domain="['|', '|', '|', '|', '|', ('x_mfrname1','ilike',self), ('x_mfrname2','ilike',self), ('x_mfrname3','ilike',self), ('x_mfrname4','ilike',self), ('x_mfrname5','ilike',self), ('x_mfrname5','ilike',self)]" /> 
     </field> 
    </field> 
</record> 

欲瞭解更多信息,請查看the Odoo Documentation

+0

不要忘記原來domain_filter的「老字號」領域,如果你想只是想延長該搜索你的領域。 – CZoellner

相關問題