KEMBAR78
How to use search fetch method in Odoo 18 | PPTX
How to use search_fetch()
method in Odoo 18
Enterprise
Enterprise
Introduction
The search_fetch is a powerful ORM method used in Odoo for some
specific addons to combine the functionality of search and read for
more efficient data fetching. It might be used to search for records
and fetch specific fields in a single call. It stores the result in the
cache memory.
Let’s discuss the various details of search_fetch in Odoo 18 in the
coming slides.
Enterprise
Basically, Odoo uses search_fetch method with the syntax
Model.search_fetch(domain, field_names[, offset=0][, limit=None][, order=None])
● domain is the search criteria we need to apply while fetching the
records. Use an empty list to match all records.
● field_names is the needed collection of all the fields. Here also,
use an empty list to get all the fields.
● offset is the number of records to skip (useful for pagination),
(default: none)
● limit is the maximum number of records to return (default: all).
● order specifies the ordering of the results (e.g., "name asc" or
"date desc").
Enterprise
As an example, we can use
self.env[‘sale.order’].search_fetch(
[('order_line','any',[('untaxed_amount_to_invoice','>',0)]),('state', '=', 'sale'),], [id,partner_id,date_order],
offset=0, limit=10,
order=asc create_date)
This code will fetch the record set containing the latest created 10 sale
orders with the domain specified in the first parameter with the values
for the fields id, partner_id and date_order.
Enterprise
search_fetch() method is faster when compared to that of search()
ORM method since the new extra parameter field_names is actually
filtering only the needed fields to get the result record set.
Typically, search_fetch() is a custom method that combines search()
and read() in a single step, providing convenience and potentially
improving performance.
By combining the two operations (search and read), search_fetch()
can optimizes the data fetching process by reducing ORM overheads
and minimizes communication between the client and server using a
single call.
For More Info.
Check our company website for related blogs
and Odoo book.
Check our YouTube channel for
functional and technical videos in Odoo.
Enterprise
www.cybrosys.com

How to use search fetch method in Odoo 18

  • 1.
    How to usesearch_fetch() method in Odoo 18 Enterprise
  • 2.
    Enterprise Introduction The search_fetch isa powerful ORM method used in Odoo for some specific addons to combine the functionality of search and read for more efficient data fetching. It might be used to search for records and fetch specific fields in a single call. It stores the result in the cache memory. Let’s discuss the various details of search_fetch in Odoo 18 in the coming slides.
  • 3.
    Enterprise Basically, Odoo usessearch_fetch method with the syntax Model.search_fetch(domain, field_names[, offset=0][, limit=None][, order=None]) ● domain is the search criteria we need to apply while fetching the records. Use an empty list to match all records. ● field_names is the needed collection of all the fields. Here also, use an empty list to get all the fields. ● offset is the number of records to skip (useful for pagination), (default: none) ● limit is the maximum number of records to return (default: all). ● order specifies the ordering of the results (e.g., "name asc" or "date desc").
  • 4.
    Enterprise As an example,we can use self.env[‘sale.order’].search_fetch( [('order_line','any',[('untaxed_amount_to_invoice','>',0)]),('state', '=', 'sale'),], [id,partner_id,date_order], offset=0, limit=10, order=asc create_date) This code will fetch the record set containing the latest created 10 sale orders with the domain specified in the first parameter with the values for the fields id, partner_id and date_order.
  • 5.
    Enterprise search_fetch() method isfaster when compared to that of search() ORM method since the new extra parameter field_names is actually filtering only the needed fields to get the result record set. Typically, search_fetch() is a custom method that combines search() and read() in a single step, providing convenience and potentially improving performance. By combining the two operations (search and read), search_fetch() can optimizes the data fetching process by reducing ORM overheads and minimizes communication between the client and server using a single call.
  • 6.
    For More Info. Checkour company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com