Thong Tran
Thong Tran

Reputation: 57

format from tuple to float in python?

def tong_thoigian (self,kr,uid,ids,context={}):
    obj=self.browse(kr,uid,ids,context=context)[0]
    kr.execute('''select name,giolam from x_giolam where name=%s'''%(obj.ma_luong))
    kq=kr.fetchall()
    tong=0.00000
    for i in kq:
          tong+=kq[1]                      
    self.write(kr,uid,ids,{'tonggiolam':tong},context=context)

the error is:

TypeError: unsupported operand type(s) for +=: 'float' and 'tuple'

I think you don't care about the table and database.... because the function that means get mayny row in table x_giolam have the atribute giolam and sum it...and then we have the salary of a staff.

Upvotes: 1

Views: 1887

Answers (1)

Paulo Scardine
Paulo Scardine

Reputation: 77271

Since the query is "select name,giolam ...", kq probably is something like:

[ ('Thong', 324.34), ('Tran', 543.34), ('Thang', 765.52) ... ]

So I think you want:

for record in kq:
    tong+=record[1]

Instead of tong+=kq[1].

Upvotes: 1

Related Questions