I'm trying to add records to my one2many fields
Py :
class employee_department(osv.osv):
_name = "employee.department"
_description = "Employee Department"
_columns = {
'deprt_id' : fields.many2one('hr.department', 'Department'),
'my_emp_ids' : fields.one2many('hr.employee', 'department_id','Employee'),
}
def onchange_department(self, cr, uid, ids, deprt_id):
employee_ids = self.search(cr, uid, [('department_id', '=', deprt_id)])
return {'value': {'my_emp_ids': employee_ids}}
employee_department()
My problem is that :
When i don't include onchange_department in my xml , my o2m fields always shows the employee assigned to no. 1 ID in my department , and so on when i save it . Example : Let's say i got 3 dept , with Admin as ID no 1 , Developer as ID no 2 and Engineer as ID no 3 . When i create it for the first time , even though the department shows at Developer , the employee printed is always Admin , it apply to next create , that always show employee in Developer and Engineer dept . And when i create for the 4th time , it doesn't show any employee at all
If i include onchange_department in my xml , i always got AttributeError: 'employee_department' object has no attribute 'onchange_department' . My xml is obviously wrong so i also need help on xml as well . Thanks in advance
my xml ( form)
<form string="Employee Department">
<field name="deprt_id" on_change="onchange_department(deprt_id, my_emp_ids)"/>
<notebook position="before">
<page string="Members">
<field name="my_emp_ids"/>
</page>
</notebook>
</form>
about not having department_id in my class , I thought that it already covered by deprt_id since it relate to hr.department , while department id also relate to hr.department as well