I am working on a custom module for Odoo 9 that interacts HR contract (model hr.contract).
My situation is that I want raise onchange event on employee_id field but the onchange method was originally written in old API with the combination of a Python method and XML definition as below:
def onchange_employee_id(self, cr, uid, ids, employee_id, context=None): if not employee_id: return {'value': {'job_id': False, 'department_id': False}} emp_obj = self.pool.get('hr.employee').browse(cr, uid, employee_id, context=context) job_id = dept_id = False if emp_obj.job_id: job_id = emp_obj.job_id.id if emp_obj.department_id: dept_id = emp_obj.department_id.id return {'value': {'job_id': job_id, 'department_id': dept_id}}
<field name="employee_id" on_change="onchange_employee_id(employee_id)"/>
I have a custom field name last_contract_id (many2one to hr.contract) and I want it to be loaded automatically on change of employee_id (just to show the contracts that owned by the selected employee.
My aim is to override it using new API which I can reuse later in Odoo 10, 11, …
How can I do it, plz?