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

I have defined a function to calculate the number of tickets, in which it needs to check whether employee took a one-way ticket or two-way ticket. if one-way, tickets should multiply by 0.5 and for two-way, it should be 1.

this is my code,


def get_no_of_tickets_used(self,cr,uid,data) 

employee_id = data.get('employee_id',False)

tkts = 0

if employee_id:

tkts_obj=self.pool['od.airfare.encashments'].search(cr,uid,[('employee_id','=',employee_id),('state','!=','refused'),('one_way','=',True)])

tkts += len(tkts_obj * 0.5 

tkts_obj=self.pool['od.airfare.encashments'].search(cr,uid,[('employee_id','=',employee_id),('state','!=','refused'),('one_way','=',False)])

tkts += len(tkts_obj * 1)

return tkts



getting an error as

File "/home/shaffaf/Documents/Client_Projects/Pizza/orchid_addons/orchid_pizza/hr/wizard/provision_xls.py", line 375, in get_no_of_tickets_used

tkts += len(tkts_obj * 0.5)

TypeError: can't multiply sequence by non-int of type 'float'


how to fix this issue?

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

Hi,

If this is your original code, there seems some mistakes in it, please update it and see whether you are getting the issue or not.

In this line ,

 tkts += len(tkts_obj * 0.5 

change it to,

tkts += len(tkts_obj) * 0.5 

Then,

change this,

tkts += len(tkts_obj * 1)

to,

tkts += len(tkts_obj) * 1

Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

@Niyas raphy thankyou, it's working.

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 5 21
3774
4
thg 10 19
9580
1
thg 2 17
4935
0
thg 1 17
4127
0
thg 12 16
2796