Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
1914 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
2
Apr 24
4277
1
Agu 25
1797
2
Agu 25
390
3
Jul 25
4532
0
Mei 25
982