In this recipe, we will use the my_library add-on module from Chapter 4, Creating Odoo Add-On Modules.
Modify the library.book model, as shown in the following model definition:
class LibraryBook(models.Model):
_name = 'library.book'
name = fields.Char('Title', required=True)
date_release = fields.Date('Release Date')
pages = fields.Integer('Number of Pages')
cost_price = fields.Float('Book Cost')
category_id = fields.Many2one('library.book.category')
author_ids = fields.Many2many('res.partner', string='Authors')
Add the library.book.category model. For simplicity, we will just add it to the same library_book.py file:
class BookCategory(models.Model):
_name = 'library.book.category'
name = fields.Char('Category')
description = fields.Text('Description')
We will be using the library.book model and getting an average cost price per category.