Enable Dark Mode!
overview-of-basic-domain-filters-in-odoo19.jpg
By: Sayed Mahir Abdulla KK

Overview of Basic Domain Filters in Odoo19

Technical Odoo 19 Odoo Enterprises Odoo Community

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

OperatorMeaning
=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

OperatorMeaning
inValue is in a list
not inValue is not in a list

Example:

[('state', 'in', ['draft', 'confirmed'])]

3) String Operators

OperatorMeaning
likeCase-sensitive partial match
ilikeCase-insensitive partial match
not likeExcludes matching text
not ilikeCase-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.


Frequently Asked Questions

Can domain filters be dynamic in Odoo?

Yes, domain filters can be dynamic by giving a variable in the value part of the domain. They can reference other field values, context variables, or be generated from Python, allowing the filter to change based on user input or business logic.

Can computed fields be used in a domain?

Only stored computed fields (store=True) can be reliably used in domain filters. Non-stored computed fields cannot be evaluated at the database level and may lead to incorrect or empty results. Give proper dependencies (@api.depends()) to specify which fields trigger recomputation.

What is the difference between the domain and the context in Odoo?

A domain controls which records are selected or displayed, while context passes parameters that affect behavior, defaults, or UI logic without filtering records directly.

Do domain filters impact performance?

Yes, complex domains with multiple OR conditions, based on operator or using non-indexed fields can affect performance. Using indexed fields, simple operators help maintain efficient queries.

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



0
Comments



Leave a comment



whatsapp_icon
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, KINFRA Techno Park
Kakkanchery, 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