Specifying model methods and using API decorators
A class in Odoo models consists of both business logic methods and field declarations. We learned how to add fields to a model in Chapter 4, Application Models. We will now see how to include business logic and methods in a model.
In this tutorial, we’ll learn how to create a function that may be used by our application’s user interface buttons or another piece of code. This method will operate on HostelRoom and take the necessary steps to modify the state of a number of rooms.
Getting ready
This tutorial assumes that you have an instance ready, with the my_hostel add-on module available, as described in Chapter 3, Creating Odoo Add-On Modules. You will need to add a state field to the HostelRoom model, which is defined as follows:
from odoo import api, fields, models class HostelRoom(models.Model): Â Â Â Â # [...] Â Â Â Â state = fields.Selection([ Â Â Â Â &...