Defining a model based on a SQL view
When working on the design of an add-on module, we model the data in classes that are then mapped to database tables by Odoo's ORM. We apply some well-known design principles, such as separation of concerns and data normalization. However, at later stages of the module design, it can be useful to aggregate data from several models in a single table, and to maybe perform some operations on them on the way, especially for reporting or producing dashboards. To make this easier, and to make use of the full power of the underlying PostgreSQL database engine in Odoo, it is possible to define a read-only model backed by a PostgreSQL view, rather than a table.
In this recipe, we will reuse the rent model from the Writing a wizard to guide the user recipe in this chapter, and we will create a new model to make it easier to gather statistics about books and authors.
For this recipe, we will use the
my_library module from the previous...