Skip to content

Feedback to user

Autorefreshing fields

v2.40.0

We have introduced autorefresh attribute for the fields in the form and tree views. This attribute is used to refresh the field automatically. This is useful when you want to update the field value based on the other fields in the form.

For example, you have a progress field in the form view, and you want to update it, you can set the autorefresh attribute to 1.

<field name="progress" widget="progressbar" autorefresh="1"/>
import threading
from osv import osv, fields
import pooler
import time
class SomeWizard(osv.osv_memory):
_name = 'some.wizard'
@classmethod
def update_progress(cls, database, uid, wiz_id, context=None):
db, pool = pooler.get_db_and_pool(database)
wiz_obj = pool.get(cls._name)
with db.cursor(readonly=True, isolation_level='repeatable read') as cr:
for progress in range(0, 101):
wiz_obj.write(cr, uid, [wiz_id], {
'progress': progress
}, context=context)
time.sleep(0.1)
return True
def start(self, cr, uid, ids, context=None):
threading.Thread(
target=SomeWizard.update_progress,
args=(cr.dbname, uid, ids[0], context),
).start()
return True
_columns = {
'progress': fields.float('Progress'),
}

Components to use