Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
1916 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
dub 24
4277
1
srp 25
1798
2
srp 25
410
3
čvc 25
4535
0
kvě 25
983