When you want data for statistics, you often need it in a grouped form, such as a monthly sales report, or a report that shows sales per customer. It is time-consuming to search records and group them manually. In this recipe, we will explore how you can use the read_group() method to access grouped data.
Accessing grouped data
How to do it...
The read_group() method is widely used for statistics and smart stat buttons. Let's assume you want to show the number of sales orders on the partner form. This can be done by searching sales orders for a customer and then counting the length:
# in res.partner model
so_count = fields.Integer(compute='_compute_so_count', string='Sale order count')
def _compute_so_count...