Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How to resolve "IndexError: tuple index out of range" in sql statement inside python?

Subscribe

Get notified when there's activity on this post

This question has been flagged
insertpostgresql9.2python2.7openerp7.0select
1 Reply
30860 Views
Avatar
Anirudh Lou

Following is my code chunks that aims to get the sum of fields/columns from a certain table:


        ...
atc_code = nature = ''
_logger.info("\n\t\t\tI was called. My method name is %s"%(str('generate_student_resource_report')))
base = amount = percent = 0.00
for ewt in self.browse(cr,uid,ids,context):
old_history = stud_re_report_line_obj.search(cr, uid, [('parent_id','=',ewt.id)],context=context)
if old_history:
stud_re_report_line_obj.unlink(cr, uid, old_history,context=context)
_logger.info("\n\t\t\tDATE FROM %s\n\t\t\tDATE TO %s"%(str(date_from),str(date_to)))
cr.execute("insert into student_resource_report_line(partner_id,seq,base_amt,\
tax_amt,percent,atc_code,parent_id,\
nature,create_date,write_date)\
select es.partner_id as partner_id,\
(case when es.name like '%WC158%' then 1\
when es.name like '%WC160%' then 2\
when es.name like '%WC010%' then 3\
when es.name like '%WC140%' then 4\
else 0 end) as seq,\
sum(es.base_amount) as base_amt,\
sum(es.tax_amount) as tax_amt,\
(case when es.name like '%EWT 1%%' then '1.00'\
when es.name like '%EWT 2%%' then '2.00'\
when es.name like '%EWT 3%%' then '3.00'\
when es.name like '%EWT 4%%' then '4.00'\
when es.name like '%EWT 5%%' then '5.00'\
when es.name like '%EWT 6%%' then '6.00'\
when es.name like '%EWT 7%%' then '7.00'\
when es.name like '%EWT 8%%' then '8.00'\
when es.name like '%EWT 9%%' then '9.00'\
when es.name like '%EWT 10%%' then '10.00'\
else null end) as percen,\
(case when es.name like '%WC158%' then 'WC158'\
when es.name like '%WC160%' then 'WC160'\
when es.name like '%WC010%' then 'WC010'\
when es.name like '%WC140%' then 'WC140'\
else null end) as atc_code,\
(case when es.name like '%WC158%' then 'NOTEBOOK'\
when es.name like '%WC160%' then 'BACKPACK'\
when es.name like '%WC010%' then 'COLOR'\
when es.name like '%WC140%' then 'BOOKS' else null end) as nature,\
(now()) as create_date,(now()) as write_date,? as parent_id\
from student_resource es where es.date between ? and ? \
group by es.partner_id,es.name",(ewt.id,ewt.date_from,ewt.date_to))
line_list = cr.fetchall()
_logger.info("\n\t\t\tSource ... %s"%(str(line_list)))
list = stud_re_report_line_obj.search(cr,uid,[('parent_id','=',ewt.id)])
lines = [line.id if line.id else False for line in stud_re_report_line_obj.browse(cr,uid,list,context=context)]
value = {
"value" : {
'name' : 'Student Resource Report',
"ewt_line" : lines
}
}
return value

My problem now is that when this method is called, It produce an error. It says:

  File "/opt/openerp/server-7/openerp/sql_db.py", line 226, in execute
res = self._obj.execute(query, params)
IndexError: tuple index out of range


and it also says that my query is bad, I dont know why? Everytime i tried it directly into PgAdmin, it works fine:


2015-08-20 01:00:10,780 5697 ERROR sample_another openerp.sql_db: bad query: insert into student_resource_report_line(partner_id,seq,base_amt, tax_at,percen,atc_code, ...

Any help/suggestion/comments is highly appreciated

0
Avatar
Discard
Avatar
Pawan
Best Answer

Anirudh,

Sql Insert command's syntax is:
"insert into [your_table_name](optional_your_fields) values([values_to enter in the fields])"

Here 'insert' and 'values' are the keywords and must be there, but i can t see and "values" keyword the in your statement.

Please check out your statement...

Hope it helps you....    

0
Avatar
Discard
Anirudh Lou
Author

Thank you for the reply. But as you see I am copying data from another table so I think it is not necessary to put "values" since its values will be equal to my select statement provided it meet its parameter in "insert into" statement.

Pawan

ops.... i missed that, ..... thanks for it...can u pls provide your error in detail....

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
Set 0 for a 'None' value which is inside a list Solved
list python2.7 openerp7.0
Avatar
Avatar
2
Dec 19
5022
How to solve TypeError: cannot concatenate 'str' and 'int' objects? Solved
date python2.7 openerp7.0
Avatar
Avatar
Avatar
Avatar
3
Aug 15
23840
How to make a dynamique _order in python ?
python2.7 openerp7.0 orderby
Avatar
Avatar
1
Mar 15
7105
want asset category(employee asset) should came in drop down of asset
postgresql postgresql9.2 python2.7
Avatar
0
Mar 15
4135
please explain this strange override super behaviour
python orm python2.7 openerp7.0
Avatar
0
Feb 16
3691
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now