Search in many2one field odoo

83 Views Asked by At

In Odoo 15, Sale order view, inside the sale order line.. we can search a product by barcode, but i want to make the search case insensitive so for example if i have two product one having barcode ='A11' and another product having a barcode ='a112' i want when i type 'a11' to get these 2 products.

the search now by odoo is case sensitive. enter image description here

1

There are 1 best solutions below

2
Kenly On

It is implemented to search for products using the = operator, It should work if you replace it with ilike

Example:

class ProductProduct(models.Model):
    _inherit = 'product.product'

    def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None):
        if args and args[0][0] == 'barcode':
            args[0] = ('barcode', 'ilike', args[0][2])
        return super(ProductProduct, self)._search(args, offset=offset, limit=limit, order=order, count=count,
                                                   access_rights_uid=access_rights_uid)