Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
6808 Ansichten

Hello everybody!!!

Guys, a am using the onchange function for a float field.

Here is my code:

def get_inputs(self, cr, uid,ids, employee_id, context=None):

ret = []

print employee_id

obj = self.pool.get('hr.employee')

obj_ids = obj.search(cr, uid, [('id','=',employee_id)])

res = obj.read(cr, uid, obj_ids, ['id', 'remaining_leaves','momo_matricule'])

for r in res :

print r['remaining_leaves']

inputs = {

'remaining_leave': r['remaining_leaves'],

}

ret += [inputs]

print ret

return ret

def on_change_employee_id(self, cr, uid, ids, employee_id, context=None):

res = {'value':{'remaining_leave': self.get_inputs(cr, uid, ids, employee_id, context=context),

}

}

return res

I have got this error: Error: [_.sprintf] expecting number but found array

Can any one help please.

Thanks a lot in advance

Best Regards.

Avatar
Verwerfen
Beste Antwort

Hi @Drees Far

For what you are doing this code will work:

def get_inputs(self, cr, uid,ids, employee_id, context=None):
obj = self.pool.get('hr.employee')
res = obj.browse(cr, uid, employee_id)
return res.remaining_leaves

def on_change_employee_id(self, cr, uid, ids, employee_id, context=None):
res = {
'value':{
'remaining_leave': self.get_inputs(cr, uid, ids, employee_id, context=context),
}
}
return res
Avatar
Verwerfen
Autor

Thanks a lot my friend. This works perfectly but plz i would like to know the reason to not have the same mistake in the futur :)

Your function get_inputs was returning a list of dicts instead of a single value for the only one employee you passed. Also no search is needed to find the employee id because you already have it.

Verknüpfte Beiträge Antworten Ansichten Aktivität
4
Dez. 19
7376
1
Feb. 16
6523
1
Dez. 15
9417
0
Aug. 15
3482
3
März 15
5634