Computed fields
Fields can have values calculated by a function, instead of simply reading a database stored value. A computed field is declared just like a regular field, but has the additional compute
argument defining the function used to calculate it.
In most cases computed fields involve writing some business logic, so we will develop this topic more in Chapter 7, ORM Application Logic - Supporting Business Processes. We will still explain them here, but will keep the business logic side as simple as possible.
Let's work on an example: Stages have a fold
field. We will add to To-do Tasks a computed field with the Folded? flag for the corresponding Stage.
We should edit the TodoTask
model in the todo_model.py
file to add the following:
# class ...
Get Odoo 10 Development Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.