简体   繁体   English

如何在Odoo中按一个字符串搜索多个自定义字段?

[英]How to search multiple custom fields by one string in Odoo?

I created a custom odoo module and now I want to make a search filter that makes it easy to search multiple fields at the same time. 我创建了一个自定义odoo模块,现在我想创建一个搜索过滤器,可以轻松地同时搜索多个字段。 I added this code to my xml and I am able to search each field individually but would like to group them into one string so the user can search all the fields (mfr name 1-6) with one search. 我将此代码添加到我的xml中,我可以单独搜索每个字段,但是希望将它们分组为一个字符串,以便用户可以通过一次搜索搜索所有字段(mfr名称1-6)。 Does anybody know if this is possible? 有人知道这是否可行?

<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>

You can use the filter_domain attribute 您可以使用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>

For further information check the Odoo Documentation 有关详细信息,请查看Odoo文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM