Fetching data in groups using read_group()
In the previous tutorials, we saw how we can search and fetch data from the database. However, sometimes, you want results by aggregating records, such as the average cost of last month’s sales order. Usually, we use group by and the aggregate function in SQL queries for such a result. Luckily, in Odoo, we have the read_group() method. In this tutorial, you will learn how to use the read_group() method to get the aggregate result.
Getting ready
In this tutorial, we will use the my_hostel add-on module from Chapter 3, Creating Odoo Add-On Modules.
Modify the hostel.room model, as shown in the following model definition:
class HostelRoom(models.Model):
    _name = 'hostel.room'
    name = fields.Char('Name', required=True)
    cost_price = fields.Float('Room Cost')
    category_id = fields.Many2one('hostel.room...