Hello odooers & developers,
Its odoo tips and tricks article, where I would like to share more knowledge about The _name_search method in Odoo 17
as an odoo developer, knowing the fundamentals of The _name_search method in Odoo 17 behaviour, its Syntax, and how we can use The _name_search method in Odoo 17 is essential.
Explore The _name_search method in Odoo 17:-
The _name_search function in Odoo 17 is an Object Relational Mapper (ORM) method designed to provide efficient and customizable searching within a specific Odoo model. It facilitates searching for records based on partial values or fields other than the default "name" field. This method is particularly useful in scenarios like:
Use of The _name_search method in Odoo 17:-
Autocompletion: When you start typing a customer name in a sales order, _name_search helps suggest matching customer records based on the entered characters.
Flexible Search Criteria: You can search for records using fields beyond the "name" field, such as email addresses, reference codes, or other relevant data points.
@api.model decorator: This decorator indicates that the method can be called without creating an instance of the model (i.e., directly on the model class).
name (str): This parameter represents the search pattern (partial value) to match against the relevant fields.
args (list, optional): This optional parameter allows you to specify additional domain criteria for the search.
operator (str, optional): This parameter defines the search operator used for comparison. By default, it's set to 'ilike' (case-insensitive like operator).
limit (int, optional): This parameter determines the maximum number of records to return in the search results.
name_get_uid (int, optional): This parameter is less commonly used and specifies the user ID for retrieving record names.
The _name_search method in Odoo 17 usage and Syntax:-
.py
from odoo import models, fields, api
class Product(models.Model):
_name = 'product.product'
_inherit = 'product.product'
@api.model
def _name_search(self, name='', args=None, operator='ilike', limit=100, name_get_uid=None):
args = args or []
if name:
args += ['|', ('name', operator, name), ('default_code', operator, name), ('description', operator, name)]
return self._search(args, limit=limit, access_rights_uid=name_get_uid).n
If you want specific odoo tips or tricks, please let us know the topic of your tips by mail at [email protected]. Then next, we would like to write a tips article based on your suggested topics, too
Devintellecs & team are odoo services providers in the USA and INDIA, so we will try our best to write the best content on your tips request
if you want to check your odoo technical or functional knowledge, then we have prepared the odoo EXam practice test for the odoo technical & functional people
Thanks, & Stay tuned for the following odoo tips soon...
How to Create name search method in Odoo 17 ?