Search Here

Search many2one field by other than name (name_search)

In this article you will learn how to search many2one field by other than "name" field. We are going to achieve this by using odoo name_search built in method.


Odoo name search Search many2one field by other than name


How to use name search function in Odoo

Problem Statement

We know that in Odoo search is available by default on "name" field. For example here is many2one field named "product". And we are unable to search on those field because this field is the combination of two field product name and product description.

Solution

We can enable search on many2one fields by other than "name" field. We can achieve this by overriding "name_search" method of Odoo.

name_search_function_in_odoo.py



Code Description


Here we override "name_search" built-in function of Odoo. Below are the descriptions of name search and its parameter.

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


Parameter Type Description
name str The name pattern to match
args list (optional) Search domain to specifying further restrictions
operator str domain operator for matching name, such as 'like', ‘ilike’, ‘=’, etc
limit int (optional) Max number of records to return
name_get_uid int To restrict or specify the user

Post a Comment

0 Comments