Domain filters are core concepts in Odoo that help restrict, search, and work with records based on defined conditions. They are used in views, actions, fields, and ORM operations to control which data is needed. In Odoo 19, domain filters continue to play a central role, offering a consistent and efficient way for both developers and functional users to manage data.
This blog explains the fundamentals of domain filters in Odoo 19, covering basic syntax, commonly used operators, and some examples to show how they are used in different situations.
Domain in Odoo:
A domain in Odoo is a structured set of conditions used to logically filter records. These domains are processed by the ORM and converted into SQL queries at runtime to get the relevant data efficiently.
Commonly used in:
- List, form, kanban, and search views
- Window actions
- Relational fields (Many2one, One2many, Many2many)
- Python ORM methods (search, search_read)
Basic Domain Syntax:
A domain is expressed as a list of tuples:
[('field_name', 'operator', 'value')]Example
[('state', '=', 'done')]This domain returns records where the state field equals ‘done’.
Common Domain Operators:
1) Comparison Operators
| Operator | Meaning |
| = | Equal to |
| != | Not equal to |
| > | Greater than |
| < | Less than |
| >= | Greater than or equal to |
| <= | Less than or equal to |
Example:
[('amount_total', '>', 1000)]2) Membership Operators
| Operator | Meaning |
| in | Value is in a list |
| not in | Value is not in a list |
Example:
[('state', 'in', ['draft', 'confirmed'])]3) String Operators
| Operator | Meaning |
| like | Case-sensitive partial match |
| ilike | Case-insensitive partial match |
| not like | Excludes matching text |
| not ilike | Case-insensitive exclusion |
Example:
[('name', 'ilike', 'invoice')]Combining Multiple Conditions (AND / OR):
AND (Default Behavior)
Multiple tuples in a domain are combined using logical AND by default.
[
('state', '=', 'sale'),
('amount_total', '>', 500)
]
This returns records where both conditions are true.
OR Conditions
Use the pipe operator | to apply logical OR.
[
'|',
('state', '=', 'draft'),
('state', '=', 'confirmed')
]
AND with Explicit Operator
Although AND is implicit, it can be written explicitly using ‘&’ instead of ‘|’.
[
'&',
('state', '=', 'sale'),
('amount_total', '>', 500)
]
Domain Filters in XML Views:
Domains are widely used in XML views, especially in relational fields.
Example 1:-
<field name="partner_id"
domain="[('is_company', '=', True)]"/>
This restricts the selection to company partners only.
Example 2:-
<field name="product_id"
domain="[('categ_id', '=', categ_id)]"/>
The domain dynamically adapts based on the current record’s categ_id.
Domain Filters in Window Actions:
Domains can be applied at the action level to control which records are displayed.
<record id="action_sale_orders" model="ir.actions.act_window">
<field name="name">Sales Orders</field>
<field name="res_model">sale.order</field>
<field name="domain">[('state', '=', 'sale')]</field>
</record>
Domains in Python (ORM):
Domains are heavily used in Python code via the ORM.
Example:-
orders = self.env['sale.order'].search([
('date_order', '>=', start_date),
('date_order', '<=', end_date)
])
Basic domain filters are a foundational part of Odoo 19 development and configuration. Whether applied in XML views, window actions, or Python ORM queries, a clear understanding of domain syntax and behavior helps developers to create efficient, scalable, and user-friendly business views and modules.
To read more about How to Add Filters Option in Website portal in Odoo 19, refer to our blog How to Add Filters Option in Website portal in Odoo 19.