Hi people,
just started learning python and openerp and I am pretty lousy so far, but I am trying.
My question is how to populate selection field with data from the database?
I have a 2 simple tables one with data of the employee(name, surname, emal, department) and the other called departments which only has department names.
When creating a new employee I would like to select the department from the dropdown populated with the departments from my other table. Pretty basic stuff.
class djelatnik(osv.osv):
_inherit= 'department
_name = 'employee'def _fetch_departments(self, cr, uid, ids, context = None):
res=[]
cr.execute('select id , department from departments')
departments=cr.fetchall()
for dep in departments:
res.append((dep.id,dep.department))
return res
_columns = {
'name': fields.char('name',size=30, required=True, help='name'),
'surname': fields.char('surname', size=30, required=True, help='surname'),
'odjel': fields.selection(_fetch_departments ,'Departments')
}
What am I doing wrong?
Ansewer updated. You change code and xml.