Getting ready

For a an easier to understand, we will add a new model to manage the book ratings. We will add a new model called library.book.rent. You can refer to the following definition to add this model:

class LibraryBookRent(models.Model):
_name = 'library.book.rent'

book_id = fields.Many2one('library.book', 'Book', required=True)
borrower_id = fields.Many2one('res.partner', 'Borrower', required=True)
state = fields.Selection([('ongoing', 'Ongoing'), ('returned', 'Returned')],
'State', default='ongoing', required=True)
book_id = fields.Many2one('library.book', 'Book', required=True)
rent_date = fields.Date(default=fields.Date.today)
return_date = fields.Date()

You will need to add a form view, an action, and a menu item to see this new model from the user interface. You will also need to add security rules for the librarian, so they can issue the book for rent. Please refer to Chapter 4, Creating Odoo Modules, if you don't know how to add these things.

Alternatively, you can use the ready-made initial module from our GitHub code examples to save time. This module will be available in the Chapter09/r0_initial_module folder. The GitHub code examples are available at https://github.com/PacktPublishing/Odoo-12-Development-Cookbook-Third-Edition.

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

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