As we want to manage the record stages dynamically, we need to create a new model. In step 1, we created a new model called library.rent.stage to store the dynamic stages. In this model, we added a few fields. One of these was the sequence field, which is used to determine the order of the stages. We also added the Boolean field fold, which is used to collapse the stages and put them in a drop-down list. This is very helpful when your business process has lots of stages because it means that you can hide insignificant stages in the drop-down menu by setting this field. We have added a book_state field to map the dynamic stage to the state of the book. We will use this field in the upcoming section.
The fold field is also used in kanban views to display folded kanban columns. Usually, Work in Progress items are expected to be in the Unfolded stage, and terminated items that are either Done or Cancelled should be in the Folded stage.
In step 2, we added the basic access right rules for the new model.
In step 3, we added the stage_id many2one field in the library.book.rent model. While creating a new loan record, we wanted to set the default stage value to Draft. To accomplish this, we added a _default_rent_stage() method. This method will fetch the record of the library.rent.stage model with the lowest sequence number so, while creating a new record, the stage with the lowest sequence will be displayed as active in the form view.
In step 4, we added the stage_id field in form view. By adding the clickable option, we made the status bar clickable. We also added an option for the fold field which will allow us to display insignificant stages in the drop-down menu.
In step 5, we added stage_id in the tree view.
In step 6, we added the default data for the stages. The user will see these basic stages after installing our module. If you want to learn more about XML data syntax, refer to the Loading data using XML files recipe in Chapter 7, Module Data.
If you don't want to do this, the kanban view provides inbuilt features for adding, removing, or modifying stages from the kanban view itself, which is coming up in the next recipe.