Skip to Content
Menu
This question has been flagged

In orderline we can search the products based on name, internal reference and barcode.I am trying to add one extra field.

Firstly I created a portno field in product template for search

port_no_1 = fields.Char(string="Port No")

in my custom module I override the function

def name_search(self, name='', args=None, operator='ilike', limit=100):

        res = super(ProductProduct, self).name_search(name='', args=None, operator='ilike', limit=100)

        ids = self.search(args + [('port_no_1', '=', name)], limit=limit)

        return res

but it will not helps search based port no

How to add this feature in my custom module ?

Avatar
Discard

When should you use name_search method: https://goo.gl/7PHhPP

Best Answer

Hello
Just Write following code name_search method of product.product object like :

def name_search(self, name='', args=None, operator='ilike', limit=100):

        res = super(ProductProduct, self).name_search(name='', args=None, operator='ilike', limit=100)

        ids = self.search(args + [('port_no_1', '=', name)], limit=limit)

         if ids:

              return ids.name_get()

        return res


Correct me,If i am wrong
Thank you

Avatar
Discard
Author

thnaks

Related Posts Replies Views Activity
1
Dec 17
1951
0
May 17
1993
1
Jul 19
3235
0
Aug 17
2202
1
Feb 17
5998