Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6960299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:23:05+00:00 2026-05-27T15:23:05+00:00

i have a function : def tong_thoigian (self,cr,uid,ids,context={}): obj=self.browse(cr,uid,ids,context=context)[0] cr.execute(”’select name,giolam from x_giolam where

  • 0

i have a function :

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

and this is table x_giolam:

class x_giolam(osv.osv):
    _name = 'x_giolam'
    _description = 'Gio Lam'
    _columns = {
                        'name': fields.integer('Lọai',size=64,required="true"),
                        'giolam' : fields.float('Gio lam',size=64,required="True"),
                        'time_in': fields.char('Gio vào',size=20),
                        'time_out' :fields.char('Gio về',size=20),
                        'congviec' :fields.char('Cong viec',size=50),
    }   
x_giolam()

and the ‘self’ is table x_salary, i think isn’t importance to say about it because i want write a function for sum salary of a staff when name=Ma_luong of table x_salary
and the error is

IndexError: list index out of range 

the type of Giolam is float…
and i write with in openerp
and i think error in line ‘tong+=kq[1]’
How can i fix it ?
thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:23:06+00:00Added an answer on May 27, 2026 at 3:23 pm

    Using my magic crystal ball, I’m guessing that cr.execute is a call to the standard database API. So kr.fetchall() will return a tuple of rows. However, it seems that your SQL is returning only a single row.

    You probably mean tong += kq[0][1], ie the second column (giolam) of the first row of the result. Alternatively, use kr.fetchone() to just get a single row, then you can keep it as kq[1]. Either way, you should check that your db call actually returns results.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

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
I have a function: def self.run_all_scheduled_reports scheduled_queries = Reports.find( :all, :joins=> 'INNER JOIN `expected_times`
I have a function: def save(self, text, *index): file.write(text + '\nResults:\n') if index ==
I have the following function: def heading_positions(self): return map( lambda h: {'{t}.{c}'.format(t=h.table_name,c=h.column_name) : h.position
I have a function like: def set_blah self.prop1 = .... if new_record? end I
Suppose I have defined a function: def hello(name:String, words:String) = println(Hello! + name +
This is a little complicated... Basically, I have this function: def do_loop(self): for line
I have a function: def create(sender, **kw): [...] Which should be called when the
I have a function foo that accepts a Boolean function def foo( f:(_)=>Boolean )
I am writing a script and in my script I have this function: def

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.