top of page

Odoo Computed Field and Compute Method

  • Writer: Tek Siong, Hock
    Tek Siong, Hock
  • Jul 3, 2021
  • 1 min read

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) 
                           
     @api.one
     @api.depends('freight_booking')
     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.

Recent Posts

See All
Odoo Performance Profile for debugging

Odoo Performance Profile for debugging, If you are on Odoo 16 and below, and need a good tool for debugging the performance of your Odoo system, this will be the right content for you.

 
 
 

Comments


Subscribe Form

  • facebook
  • linkedin

©2019 by Excelroot Technology Sdn Bhd.

bottom of page