Adding relational fields to a Model
Relations between Odoo Models are represented by relational fields. We can have three different types of relations: many-to-one, one-to-many, and many-to-many. Looking at the Library Books example, we see that each book can have one Publisher, so we can have a many-to-one relation between books and publishers.
Looking at it from the Publishers point of view, each Publisher can have many Books. So, the previous many-to-one relation implies a one-to-many reverse relation.
Finally, there are cases where we can have a many-to-many relation. In our example, each book can have several (many) Authors. And inversely, each Author can have written many books. Looking at it from either side, this is a many-to-many relation.
Getting ready
We will reuse the my_module
addon module from Chapter 3, Creating Odoo Modules.
How to do it…
Odoo uses the Partner model, res.partner
, to represent persons, organizations, and addresses. So, we should use it for authors and publishers...