Enable Dark Mode!
how-to-use-search-domain-operators-in-odoo-17.jpg
By: Hridhya D

How to Use Search Domain Operators in Odoo 17

Technical

Several conditions and operators make up a search domain, which determines which records match the specific requirements. Each condition in the domain tends to be a triple (field_name, operator, value)consisting of a field name, an operator, and a value.
domain="[(field_name, 'operator', value)]"

1. Equal (=)

The equal operator (=) is used to find records that exactly match a given value.
For example, the domain [('name', '=', 'Johnson’)] is used to find all customers with the name "'Johnson."

2. Not Equal Operator (!=)

The not-equal operator (!=) does the opposite. It helps you find records that do not match a specified value. To locate all customers whose names are not "'Johnson" eg:- [('name', '!=', 'Johnson’)].

3. Greater Than (>)

This operator (>) is essential for filtering records based on numerical or date values. For example, to find all sales orders with a total amount greater than $1,500, you can use [('amount_total', '>', 1500)].

4. Less Than (<)

This operator (<) is essential for filtering records based on numerical or date values. For example, to find all sales orders with a total amount less than $1,500, you can use [('amount_total', '>', 1500)].

5. Greater Than or Equal to (>=) 

This operator is similar to greater than operator, this operator (>=) include records where the field value is equal to the specified value. For instance, to find all employees born on or after January 1, 1990, we can use [('birthdate', '>=', '1990-01-01')].

6. Less Than or Equal to (<=)

This operator is similar to less than the operator, this operator (<=) include records where the field value is equal to the specified value. For instance, to find all employees born on or before January 1, 1990, you'd apply [('birthdate', '<=', '1990-01-01')].

7. Like Operator ('like') 

The like operator in Odoo is used for case-sensitive text matching to filter records.To find records whose names contain ‘Johnson’ in a case-sensitive manner.
[('name', 'like', ‘Johnson’)]
This will retrieve records where the 'name' field contains 'John' with the exact same letter case. It won't match names like ‘JohnSon’ or ‘JoHnsoN’.

8. Not Like Operator ('not like')

The not like operator in Odoo is used to filter records that do not contain a specific string in a case-sensitive manner. To find partners whose names do not contain ‘Johnson’ in a case-sensitive way:
[('name', 'not like', ‘Johnson’)]
This will retrieve records where the 'name' field does not contain ‘Johnson’ with the exact same letter case.

9. In Operator ('in')

The in operator helps you find records where a field's value is one of the specified values in a list eg:-  [('order_number', 'in', [101, 1002, 1003])].

10. Not In Operator ('not in')

The not in operator identifies records where the field's value is not in the list eg:- [('order_number', 'not in', [101, 1002, 1003])].

11. Ilike Operator

The ilike operator in Odoo is used for case-insensitive text matching. It helps you find records that contain a specific string, regardless of letter case.
[('name', 'ilike', 'Johnson)]
In this example, you're searching for records where the 'name' field contains the string ‘Johnson’ in a case-insensitive manner using the ilike operator. This will match 'JoHnson,' 'JohnsoN,' 'JOHNson,' and other variations.

12. not ilike Operator

The NOT ilike operator in Odoo is used to filter records that do not contain a specific string in a case-insensitive manner.
E.g.:- To find records whose names do not contain ‘Johnson’ in a case-insensitive way eg:-  [('name', 'not ilike', ‘Johnson’)].

13. =?

The =? operator in Odoo is used to filter records where a field's value is exactly equal to a specified value. Assume you have a model named sale.order for managing sales orders in Odoo. To find sales orders with the 'state' field exactly equal to 'done' eg:-  [('state', '=?', 'done')].

14. Child_of

In Odoo, the child_of domain operator is used to filter records that are either the specified record or any of its children in a hierarchical structure, such as parent-child relationships.
Assume you have a model named hr.employee for employee records in Odoo. You want to find all employees under a specific department, including the department manager (i.e., children and the manager).
employees = self.env['hr.employee'].search([('department_id', 'child_of', department_id)]). 
Hence, search domain operators are mainly used to filter Odoo records and make it easier to check for the specific conditions we wish to apply.
To read more about creating name search function in Odoo 16, refer to our blog How to Create Name Search Function in Odoo 16


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment



whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message