Skip to Content
Menu
This question has been flagged
1 Reply
1892 Views

I have seen both used in the code, and I am wondering what the difference is.


This is what I see in the documentation:


https://www.odoo.com/documentation/17.0/developer/reference/backend/orm.html

Avatar
Discard
Best Answer

self.filtered(func)

self.filtered_domain(domain)

  • Filters a recordset based on a Python function
  • Requires all records to be retrieved from the database so they can be evaluated by the function
  • Used when filtering can't be done with a domain
  • Slower for large datasets, less scalable
  • Filters a recordset based on an ORM domain
  • Filtering done in PostgreSQL, only returning those records that match the domain
  • Faster for large datasets, more scalable


Use self.filtered_domain wherever possible for performance reasons and use self.filtered for cases where you can't leverage the Odoo domain syntax.

Use self.filtered when:

  • You need to filter based on complex conditions that cannot be represented by a domain.
  • You need to filter using Python logic, like checking computed fields or applying custom methods.

Use self.filtered_domain when:

  • The filtering conditions can be expressed as a domain.
  • You are working with large datasets and want to optimize performance by offloading filtering to the database.


Avatar
Discard
Related Posts Replies Views Activity
2
Apr 24
4254
1
Aug 25
1775
2
Aug 25
371
3
Jul 25
4482
0
May 25
955