This question has been flagged
1 Reply
4123 Views

_columns={

    '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 [])

  nb_employees=nb_employees+1

      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

Avatar
Discard
Best Answer

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.

Avatar
Discard

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?

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.

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