Getting ready

For this recipe, we will continue to use the my_library module from the last recipe. Make sure that you have the library.book.categroy model in the my_library module.

For this recipe, we will create a new module called my_library_return, which depends on the my_library module. In this module, we will manage return dates for the borrowed book. We will also automatically calculate the return date based on the category.

In the Adding features to a Model using inheritance recipe in Chapter 5, Application Models, we saw how to add a field in the existing model. In this module, extend the library.book model, as follows:

class LibraryBook(models.Model):
_inherit = 'library.book'

date_return = fields.Date('Date to return')

Then, extend the library.book.category model, as follows:

class LibraryBookCategory(models.Model):
_inherit = 'library.book.category'

max_borrow_days = fields.Integer(
'Maximum borrow days',
help="For how many days book can be borrowed",
default=10)

To add this field in views, you need to follow the Changing existing views view inheritance recipe from chapter 10, Backend Views. You can find a full example of the code 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