When working on the design of an addon module, we model the data in classes that are then mapped to database tables by Odoo. We apply some well-known design principles such as separation of concerns, data normalization, and more. However, at later stages of the module design, it can become meaningful to aggregate data from several models in a single table, and maybe perform some operations on them on the way, especially for reporting or producing dashboards. To ease doing so, and to leverage 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 loan model from the Write a wizard to guide the user recipe in this chapter, and create a new model to ease gathering statistics about book turnover, the age of...