Odoo Help

Welcome!

This community 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.

0

database not getting updated by on change event

By
mihir shah
on 6/21/13, 4:24 AM 1,147 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

2
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?

Aldennis
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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