The archive feature certainly deserves its own add-on module, or at least its own Python code file. However, to keep the explanation as simple as possible, we will cram it into the models/library_book.py file:
- Add the abstract model for the archive feature. It must be defined in the Library Book model, where it will be used:
class BaseArchive(models.AbstractModel): _name = 'base.archive' active = fields.Boolean(default=True) def do_archive(self): for record in self: record.active = not record.active
- Now, we will edit the Library Book model to inherit the Archive model:
class LibraryBook(models.Model): _name = 'library.book' _inherit = ['base.archive'] # ...
An upgrade of the add-on module is needed for the changes to be activated.