How to do it...

In order to add a button, you need to perform the following steps:

  1. Update the definition of the state field to have a lost state:
state = fields.Selection([('ongoing', 'Ongoing'), 
('returned', 'Returned'), ('lost', 'Lost')],
'State', default='ongoing', required=True)
  1. Add a Mark as lost button in the form view of library.book.rent:
<button name="book_lost" string="Lost the Book" states="ongoing" type="object"/>
  1. Add the book_lost() method in the library.book.rent model:
   def book_lost(self):
...
  1. In the method, make sure that we are acting on a single record, and then change the state:
self.ensure_one()
self.state = 'lost'
  1. Add the following code in the method to change the context of the environment and call the method to change the book's state to lost:
book_with_different_context = self.book_id.with_context(avoid_deactivate=True)
book_with_different_context.make_lost()
  1. Update the make_lost() method of the library.book model to have a different behavior:
def make_lost(self):
self.ensure_one()
self.state = 'lost'
if not self.env.context.get('avoid_deactivate'):
self.active = False
..................Content has been hidden....................

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