In Odoo, the name search function is used to search records of a model in a relational field with a partial value or with fields other than the record's default name. For instance, when searching records in a Many2one field, by default, when we type the record name, we can search and choose from the records that are already there.
2. ● name_search() is an Odoo ORM method that is responsible for searching
some specific record by some field values in a relational field.
● In Odoo, the name search function is used to search records of a model in a
relational field with a partial value or with fields other than the record's
default name. For instance, when searching records in a Many2one field, by
default, when we type the record name, we can search and choose from the
records that are already there. However, we may use the name_search
function to search using various parameters.
4. When we create a record in that form with a customer field, we can search
existing records when we type the customer’s name. Also, when we type the
phone number of the contact, we can search that particular record.
In this example, the phone number of the contact.
6. here you can see no customer is found but using name_search function you can do this.
7. If we search in the customer’s field using this phone number, we can
get a list of contacts with this phone number. Also, you can see that
we can search using a partial value of name or phone number.
This property is achieved using the name search function.
Let’s see how the name search function is defined.
8.
9. The parameters of the function are:
name (str): The name pattern to match
args (list): Optional search domain to specify further restrictions
operator (str): domain operator for matching names,
such as 'like', ‘ilike’, ‘=’, etc.
limit (int): Optional to limit the maximum number of records to
be returned.
name_get_uid: To specify the user or to restrict users
10. Suppose we require that we also add an email address for searching
for customers. For that, we have to define a name search function in
"res.partner’ by inheriting the model.
By default, the value of args is given as None. We can provide the
conditions we need for the name search function as a domain and
append the args list inside the function.
11. Now we can search the contacts using the phone number.
13. Check our company website
for related blogs and Odoo book.
Check our YouTube channel for
functional and technical videos in Odoo.
https://www.youtube.com/watch?v=ub4kLrTQVNk