top of page
  • Writer's pictureTek Siong, Hock

Odoo Computed Field and Compute Method

Updated: May 20, 2022

Odoo compute method is a quick way to set the default values or recalculate a value whenever the view is opened by user. There are a few characteristics that worth to take note at:

  1. Add store=True, so that the field value will be stored in the database for reporting (pivot table), etc. The downside is that it will not recomputed whenever the view is open or not recompute whenever the dependency fields are changed for second time.

     booking_date = fields.Date(string='ETA/ETD Date', copy=False,
                           compute="_compute_booking_date", store=True) 
     def _compute_booking_date(self):
     if self.freight_booking:
        self.booking_date = self.freight_booking.booking_date_time        

2. Once deployed, the field values will be updated for all the records (even historical).

3. If you later decided to remove the compute from the field, with the store=true, the field values will still be preserved.

4. The compute field will always be read only. However, there is an inverse method to make it editable

booking_date = fields.Date(string='ETA/ETD Date', copy=False,
                           compute="_compute_booking_date", store=True, inverse="_inverse_booking_date")

Click "Like" at the bottom of this blog, to motivate us to continue sharing more Odoo tips.

1,779 views0 comments

Recent Posts

See All

Odoo with AI ChatGPT

Let the AI answer your questions based on your Odoo data

bottom of page