1
votes

In hr.holidays model for employee_id field onchange function is there but I removed that onchange function from 'employee_id' field.The main aim of that function is Auto filling of 'department_id' field of same model when the change of 'employee_id' field.

problem:

My requirement is the below code is existing in odoo v7 but i need in odoo v8. I tried in different ways but I didn't get any result so please help me.

def onchange_employee(self, cr, uid, ids, employee_id):
    result = {'value': {'department_id': False}}
    if employee_id:
        employee = self.pool.get('hr.employee').browse(cr, uid, employee_id)
        result['value'] = {'department_id': employee.department_id.id}
    return result

My odoo V8 code:

I am getting object of 'hr.employee' but I am unable to fill that object in 'department_id' field because of it is many2one field.Below is my code.

@api.onchange('employee_id')
@api.constrains('employee_id')
def joining_date(self):
    if self.employee_id:
        self.department_id =''
        depart_obj = self.env['hr.employee'].search([('name', '=' , self.employee_id.name)])
        if depart_obj:
            for departments in depart_obj:
                depart_new_obj = self.env['hr.employee'].browse([departments.id])

                for tax in depart_new_obj.department_id:
                    self.department_id = [tax.id]
2

2 Answers

1
votes

Why are you searching and browsing object if you have already object of self.employee_id

just set

self.department_id = self.employee_id.department_id.id
1
votes

At finally I got the answer removing of [ ] .""self.department_id = tax.id""