Odoo provides two inheritance mechanisms to extend an existing model in a modular way. With the Odoo inheritance mechanims, you can:
- add or override fields, methods, constraints on an existing model;
- factor out some generic code in model mixins;
- associate each records from a model with a parent record from another model.
The purpose of this module is to learn these inheritance mechanisms.
We assume that both session instructors and session attendees relate to the
general model for contacts, namely res.partner
. The model fits well for
attendees, but is not specific enough for instructors: not every contact may be
assigned as instructor for a session.
Extend the model res.partner
with a boolean field instructor
, which allows
to distinguish between instructors and other contacts. Also add a read-only
field that shows the sessions attended by a given contact. Modify the instructor
field on sessions such that only contacts marked as instructors can be selected.
In the given code, a menu and specific views are defined for contacts in the context of courses. Modify the views to show the new fields. There exists another, modular way of modifying views, but this is the subject of the training module View Inheritance.
- Hint: Use a domain on relational fields to restrict which records may be selected
With our application, Brussel's library can now manage the rentals of books by customers. However, the librarians are not happy with the solution. The library usually has several copies of a given book, which makes the list of books full of redundant data. Moreover, they want to identify each copy of a book with a unique reference, which is internal to the library. Rentals should relate to the actual book copy that is borrowed.
Add a specific data model for book copies. All the copies of a book should share the same, unique, book data (title, authors, ISBN, etc.) Every book copy should have a unique internal reference. Rentals should relate to book copies instead of books.
- Hint: Use delegation inheritance for book copies.