Skip to Content
Menu
This question has been flagged
1 Reply
2144 Views

hi, 

Anyone knows how to stop odoo from computing stored field after running the server?


In my case, when adding store=True to sale_order_count field, the system goes down after several minutes because it hits the timeout limit (Odoo.sh) ( trying to compute and store value for ~800K records).


AFAIK, when you stop the server and then restart it, Odoo should not launch the computation of the field again. but in my case, it does it after every restart...leading to timeout each time.


--UPDATE-- 


I don't want to add search attribute. I just remember that Odoo support told me to call a method that prevents triggering compute field after restarting the system but they did not tell me its name.. So i assume someone in the community would know about it.


Thanks.

Avatar
Discard
Best Answer

when you have a stored computed field with store=True, the system will attempt to compute and store the value of the field for all existing records when you first start the server after adding or modifying the field. This behavior can be problematic if you have a large number of records, as it can lead to timeouts or performance issues.

from odoo import models, fields, api

class MyModel(models.Model):
_name = 'my.model'

# Dependent fields
field1 = fields.Char()
field2 = fields.Integer()

# Computed field
computed_field = fields.Integer(compute='_compute_field', store=True, depends=['field1', 'field2'])

@api.depends('field1', 'field2')
def _compute_field(self):
for record in self:
# Compute the value for the field
record.computed_field = record.field1 + record.field2


In the example above, the computed_field depends on field1 and field2. When you start the server, Odoo will check if the values of fields 1 and field2 have changed since the last computation. If they haven't, it will skip the computation of the computed_field. This can help prevent the timeouts you're experiencing.

Avatar
Discard
Author

thanks for your reply,

I don't agree with you regarding skipping compute if fields 1 and field2 didn't change after Server restart.

Adding depends does not skip the computation after server restart. knowing that depends fields are not changed since the last computation as you mentioned.

The compute function is a bit tricky in my case, you can check "_compute_sale_order_count" in Partners and tell me what depends you want to add ?

Thanks.

Related Posts Replies Views Activity
0
Apr 24
929
2
Sep 22
2186
1
May 25
190
0
May 25
220
1
May 25
574