Setting values using expressions

A more elaborate alternative for setting a field value is the eval attribute. It evaluates a Python expression and assigns the result to the field.

The expression is evaluated in a context that, besides Python built-ins, also has some additional identifiers available. Let's have a look at them.

To handle dates, the following Python modules are available: time, datetime, timedelta, and relativedelta. They allow you to calculate date values, something that is frequently used in demonstration and test data, so that the dates used are close to the module installation date. For more information about these Python modules see the documentation at https://docs.python.org/3/library/datatypes.html.

For example, to ...

Get Odoo 11 Development Essentials - Third Edition 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.