There's more...

Notice that we have the state field on the library.book model. This field is used to represent the status of the book, or, in other words, whether it is available or not. We have added a book_state field to map the state of the book with the dynamic stages.

In order to reflect the book state from the stage, we need to override the create and write methods in the library.book.rent model, as follows:

    @api.model
def create(self, vals):
rent = super(LibraryBookRent, self).create(vals)
if rent.stage_id.book_state:
rent.book_id.state = rent.stage_id.book_state
return rent

@api.multi
def write(self, vals):
rent = super(LibraryBookRent, self).write(vals)
if self.stage_id.book_state:
self.book_id.state = self.stage_id.book_state
return rent

After this, whenever the user changes the stage of any loan record, it will be reflected in the book record.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset