Silviaa
Silviaa

Reputation: 485

Odoo Search Domain Filter with multiple values

i have row like below Structure:

 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

when i search the barcode with barcode like 378 it will display only one row ..

 Orange dozen    378

i want to display all the 3 rows .. with any barcode ..

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

MY select Query like :

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

How to resolve it ?

Upvotes: 0

Views: 4625

Answers (2)

Atul Arvind
Atul Arvind

Reputation: 16773

name_search will do a job for you in odoo to extend the search result.

Here is a basic name_search method you can modify according to your need in your model.

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)

kindly change the field name in the search args according to your field in the model.

hope this helps!

Upvotes: 1

user2175784
user2175784

Reputation: 183

Try to use this filter :

filter_domain="[(self, 'in', ['barcode_one', 'barcode_two','barcode_three','barcode_four'])]"

Upvotes: 0

Related Questions