Copy model definition using inheritance
We have seen class inheritance (extension) in the previous recipe. Now we will see prototype inheritance, which is used to copy the entire definition of the existing model. In this recipe, we will make a copy of the library.book model.
Getting ready
We will continue using the my_library add-on module from the previous recipe.
How to do it...
Prototype inheritance is executed by using the _name and _inherit class attributes at the same time. Perform the following steps to generate a copy of the library.book model:
- Add new file called
library_book_copy.pyto the/my_library/models/directory. - Add the following content to the
in library_book_copy.pyfile:from odoo import models, fields, api class LibraryBookCopy(models.Model): Â Â Â Â _name = "library.book.copy" Â Â Â Â _inherit = "library.book" Â Â Â Â _description = "Library Book's Copy"
...