Odoo allows us to compute the value of a field either with respect to some other
fields or without depending on other fields using code. Odoo studio module helps
us to write a Compute function from the user interface. We can Take a look at a
small compute function for calculating the total of a purchase order.
Under the ‘Total’ field we need the total of this purchase order.
When we toggle to Studio and click on the Total field then on the left hand side
under Properties tab we have a ‘more’ option.
After clicking on the More option we have the ‘Dependencies’ and ‘Compute’ options
under Properties Tab.
The next step is to add our ‘dependencies’ and ‘compute function’. Under dependencies
we need to mention the fields that are related to the compute method. Compute function
performs its calculation with respect to those fields.
There are some predefined variables we can use them for a compute function,
Self: Contain a 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 timezone or calculate relative delta between two dates
they are possible using dateutil package.
Time: Python module for deal with time
Also we can access other features through ‘self’, ‘self.env’.
Now the compute method calculates the total of this purchase order. Similarly we
can add the compute method to the fields.