Adding a stat button to a form view
Odoo uses a stat button to relate two different objects visually on the form view. It is used to show some basic KPIs for related records. It is also used to redirect and open another view. In this recipe, we will add a stat button to the form view of a room. This stat button will display the count of room records and on clicking it, we will be redirected to the list of Kanban views.
Getting started
For this recipe, we will be using the my_hostel
module from the previous recipe.
How to do it...
Follow these steps to add a stat button to the hostel’s form view:
- Add the
rooms_count
compute field to thehostel.hostel
model. This field will count the number of active rooms in the hostel:rooms_count = fields.Integer(compute="_compute_rooms_count") def _compute_rooms_count(self): Â Â Â Â Â Â Â Â room_obj = self.env['hostel.room'] Â Â Â Â Â Â Â Â ...