Odoo搜索域过滤器具有多个值

时间:2017-03-09 04:22:14

标签: search filter openerp

我的行如下:结构:

 Product  UOM    Barcode_one Barcode_Two Barcode_three Barcode_four price

 Orange   unit      123       456         789          457      23
 Orange   dozen                            378                  210
 orange   pack      222       29437                             200
 apple    unit      345                                         60

当我用条形码(如378)搜索条形码时,它只显示一行..

 Orange dozen    378

我想用任何条形码显示所有3行..

我的XML

 <search string="Search Product by Barcode">
        <field name="name" string="Barcode"
            filter_domain="['|','|','|', 
              ('barcode_one','ilike',self),
              ('barcode_two','ilike',self), 
              ('barcode_three', 'ilike', self),
              ('barcode_four', 'ilike', self),                
              ]"/>
            <field name="related_categ_id"/> 
            <field name="related_type"/>    
            <field name="related_group_id"/>                        
        </search>

我选择查询,如:

Select * from product_pricelist_item 
where 
barcode_one ilike '29437' 
or barcode_two ilike '29437' 
or barcode_three ilike '29437' 
or barcode_four ilike '29437' 
or product_tmpl_id in ( Select product_tmpl_id from                              
product_pricelist_item  where 
barcode_one ilike '29437' 
or barcode_two ilike '29437' 
or barcode_three ilike '29437' 
or barcode_four ilike '29437') 

如何解决?

2 个答案:

答案 0 :(得分:1)

name_search 将在odoo中为您完成工作,以扩展搜索结果。

这是一个基本的name_search方法,您可以根据模型中的需要进行修改。

def name_search(self, name, args=None, operator='ilike', limit=100):
    if not args:
        args = []
    if name:
        args += ['|', '|', '|', ("barcode_one", operator, name), ("barcode_two", operator, name), ("barcode_three", operator, name), ("barcode_four", operator, name)]
    return super(Product, self).name_search(name, args=args, operator=operator, limit=limit)

根据模型中的字段更改搜索参数中的字段名称。

希望这有帮助!

答案 1 :(得分:0)

尝试使用此过滤器:

  

filter_domain =&#34; [(自我,&#39; in&#39;,[&#39; barcode_one&#39;,   &#39; barcode_two&#39;&#39; barcode_three&#39;&#39; barcode_four&#39;])]&#34;

相关问题