Odoo Help


database not getting updated by on change event

mihir shah
on 6/21/13, 4:24 AM 1,657 views


    'salary': fields.integer("Salary" ),

            'increment_date':fields.date('Next increment Date'),

    'department_id':fields.many2one('hr.department', 'Department'),
    'parent_id': fields.many2one('hr.employee', 'Manager'),
    'job_id': fields.many2one('hr.job', 'Job'),
            'coach_id': fields.many2one('hr.employee', 'Coach'),
     'employee_id':fields.many2one('hr.employee','HR employee'),

def on_change_job(self, cursor, user, field,jobid, context=None): res = {} if not jobid: return res
job= self.pool.get('hr.job').browse(cursor, user,jobid)

  nb_employees = len(job.employee_ids or [])


      res[job.id] = {
              'no_of_employee': nb_employees,
              'expected_employees': nb_employees + job.no_of_recruitment,

      return res

on change job event values which are returned are ohk but the effect is not seen in database, values of the fields does not get updated.

i can use update query but .....i want to try it using ORM

Torsten Francke
On 6/21/13, 9:46 AM

on_change is only to update the form of the UI, so by default this is a feature ;)

if you want to save data to the database you have to call a write method, but using write inside on_change is bad design. In a form the user expect that the data will by only save on clicking the "save" button and no autosave on change events.

I have a button that runs a function on the one2many field objects in the form. I need the on_change event to save it. How can I achieve that?

on 7/20/13, 7:46 AM

If you save a object in your form all relatet (one2many) will also save. As i menation auto-save wit on_change is not was the user expect and bad design. Let the user control when he wants to save a form.

initOS GmbH, Torsten Francke
on 7/22/13, 6:10 AM

I think what your are looking for is wizard: https://doc.openerp.com/v6.1/developer/04_wizard/

initOS GmbH, Torsten Francke
on 7/22/13, 6:11 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 6/21/13, 4:24 AM
Seen: 1657 times
Last updated: 3/16/15, 8:10 AM