Odoo 15 Studio Book - Define Compute Method For a Field

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.

odoo-studio-book

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.

odoo-studio-book

After clicking on the More option we have the ‘Dependencies’ and ‘Compute’ options under Properties Tab.

odoo-studio-book

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’.

odoo-studio-book

Now the compute method calculates the total of this purchase order. Similarly we can add the compute method to the fields.

odoo-studio-book
whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message