Odoo allows users to calculate field values in two ways. One is dependent on other
fields, and the other is not dependent on any other fields. The Odoo Studio module helps
create compute fields easily in the UI.
We can discuss a computation function for a field to show the total product quantity of
that order.
Now we can add the field Total Product Quantity. In this field, we need to calculate the
total product quantity.
After opening the studio window, we need to select this field. Under Properties, we have
an option ‘More’.
After clicking the "More" option, we need to define the dependencies and compute.
In the dependencies, you should write fields that are related to the compute method.
The compute function returns a value after the calculation for each record.
There are some predefined variables available in Odoo.
- Self: The set of records to compute
- Datetime: Supply classes to work with date and time
- Dateutil: Using the dateutil module, we can expand the datetime module.
When we need to show the timezone or calculate the
relative delta between two dates, they are possible
to use dateutil package.
- Python module for dealing with time
In this way, we can add compute method for any field.