ORM Method: Name search in Odoo

ORM Method: Name search in Odoo

This blog is all about ORM Method: Name search in Odoo.  As per one of our customer requirement, In HR module, in employee search form they wanted to display some particular kind of records in one search result, there were many fields and status that we had in our one record, and for all we needed to filter them on some status basis or at some places with the employee grade, role,status, type of employees etc.

To make it possible we used name search function, which is specially used for many2one fields for filter, display of records to the end users.

We used below piece of code, in this, we took the scenario for the filter where in the filter we wanted to search and display the list of employees who have resigned.

Sample Code:

def name_search(self, cr, user, name=”, args=None, operator=’ilike’, context=None, limit=100):
if context is None:
context = {}
if args is None:
args = []
args.extend([(‘status’,’=’,’resign’)])
res = super(self.__class__, self).name_search(self, cr, user, name=”, args=args, operator=operator, context=context, limit=limit)
return res

By this when user will select the status as ‘resign’ in filter for search against many records of different status.

You must be logged in to post a comment.