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 book. This stat button will display the count of rent records and on clicking it, we will be redirected to the list of kanban views.
For this recipe, we will be using the
my_library module from the previous recipe.
How to do it...
Follow these steps to add a stat button to the book's form view:
- Add the
rent_countcompute field to the
library.bookmodel. This field will count the number of rent orders for a book:
rent_count = fields.Integer(compute="_compute_rent_count") def _compute_rent_count(self): BookRent = self.env['library.book.rent'] for book in self: ...