コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
6813 ビュー

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.

アバター
破棄
最善の回答

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
アバター
破棄
著作者

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.

関連投稿 返信 ビュー 活動
4
12月 19
7380
1
2月 16
6524
1
12月 15
9418
0
8月 15
3484
3
3月 15
5634