KEMBAR78
How to use read_group method in Odoo 18 | PPTX
How to use read_group
method in Odoo 18
Enterprise
Enterprise
Introduction
In Odoo, the read_group method is a powerful ORM feature used to
retrieve and aggregate data efficiently by grouping records based
on specified fields.
Let’s discuss the various details of read_group() in Odoo 18 in the
coming slides.
Enterprise
This method is particularly useful for generating reports and
performing data analysis without the need to fetch all records into
memory.
This read_group() has the syntax
read_group(domain, fields, groupby, offset=0, limit=None, orderby=False,
lazy=True)
Enterprise
Here,
● domain: The list specifying the search criteria to filter records.
● fields: A list of fields to include in the result, with optional
aggregation functions.
● groupby: A list of field names to group the records by
● offset: Number of records to skip (default is 0).
● limit: The maximum number of records to return.
● orderby: Specifies the order of the results.
● lazy: If set to True, the method may split read_group into
multiple calls for better performance on large datasets.
Enterprise
Suppose we have a model student.student with fields name,
total_grade, and category_id. To calculate the average total_grade
for each category_id, we can use the read_group method as
follows:​
grouped_result =
self.env['student.student'].read_group(
domain=[('total_grade', '!=', False)],
fields=['category_id', 'total_grade:avg'],
groupby=['category_id'] )
Enterprise
Here, the domain filter out records where 'total_grade' is not set.
To retrieve the fields and aggregate, we use the fields attribute.
And the groupby specifies the field to group by.
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 read_group method in Odoo 18

  • 1.
    How to useread_group method in Odoo 18 Enterprise
  • 2.
    Enterprise Introduction In Odoo, theread_group method is a powerful ORM feature used to retrieve and aggregate data efficiently by grouping records based on specified fields. Let’s discuss the various details of read_group() in Odoo 18 in the coming slides.
  • 3.
    Enterprise This method isparticularly useful for generating reports and performing data analysis without the need to fetch all records into memory. This read_group() has the syntax read_group(domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True)
  • 4.
    Enterprise Here, ● domain: Thelist specifying the search criteria to filter records. ● fields: A list of fields to include in the result, with optional aggregation functions. ● groupby: A list of field names to group the records by ● offset: Number of records to skip (default is 0). ● limit: The maximum number of records to return. ● orderby: Specifies the order of the results. ● lazy: If set to True, the method may split read_group into multiple calls for better performance on large datasets.
  • 5.
    Enterprise Suppose we havea model student.student with fields name, total_grade, and category_id. To calculate the average total_grade for each category_id, we can use the read_group method as follows:​ grouped_result = self.env['student.student'].read_group( domain=[('total_grade', '!=', False)], fields=['category_id', 'total_grade:avg'], groupby=['category_id'] )
  • 6.
    Enterprise Here, the domainfilter out records where 'total_grade' is not set. To retrieve the fields and aggregate, we use the fields attribute. And the groupby specifies the field to group by.
  • 7.
    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