Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
6859 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Tác giả

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.

Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 12 19
7422
1
thg 2 16
6560
1
thg 12 15
9478
0
thg 8 15
3539
3
thg 3 15
5694