Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

IndexError: list index out of range need a help............. please check this code

By
Odoo
on 6/10/14, 4:37 AM 798 views

When I click on this  check_eligibility  button ---  it shows error   IndexError: list index out of range, Then how to change my code........for error free

 

from osv import osv,fields
import time
from datetime import datetime
from datetime import timedelta

class mech_info(osv.osv):
    
    _inherit='hr.employee'
    
    _columns={
              'date_of_join' :fields.date('Date of Join',required=True),
               'current_date':fields.date('Applied date',require=True),
               'eligible_details':fields.text('Eligibility Details')
                             }
    
    def  check_eligibility(self,cr,uid,ids,context=None):
         day_obj=self.read(cr,uid,ids,['date_of_join','current_date'],context=context)
         
         calc_vacation=self.pool.get('scheme.type.info').read(cr,uid,ids,['interval','criteria','scheme_id'],context=context)
         
         
         dateformat="%Y-%m-%d"
         d1=datetime.strptime(day_obj[0]['date_of_join'],dateformat)
         d2=datetime.strptime(day_obj[0]['current_date'],dateformat)
         v1=d2-d1
         
         total_days=v1.days
       
         if total_days<=calc_vacation[0]['interval']:
             msg=calc_vacation[0]['criteria']
         elif total_days<=calc_vacation[0]['interval']:
              msg=calc_vacation[0]['criteria']
         else:
             msg=calc_vacation[0]['criteria']            
         vals={
               'eligible_details':msg
               }
         self.write(cr,uid,ids,vals)
        
         return True
     
mech_info()

 

 

class scheme_type_info(osv.osv):
    
    _name='scheme.type.info'
    
    _columns={
              'scheme_id':fields.integer('Scheme Type',required=True,size=50),
              'interval':fields.integer('interval type ',required=True,size=64),
              'criteria':fields.text('vacation criteria',required=True,size=50),
              'active':fields.boolean('Active')
              }
    
scheme_type_info()

 

 

 

 

0
Ivan
On 6/10/14, 4:56 AM

Seams ids = None or just 1 id not in a list.
read(cr, uid, 1, ...) 
>> {...}

read(cr, uid, [1,...])
>> [{...},]

So, you need add condition on not empty ids and if ids is not a list convert it to list. Also check what you received after read. I mean day_obj and calc_vacation.

 

Also I see that you trying read same ids from 2 different models: hr.employee(self) and scheme.type.info. Seams you need some other ids for second one.

Hi here i attached my module code---------- from osv import osv,fields import time from datetime import datetime from datetime import timedelta class mech_info(osv.osv): _inherit='hr.employee' _columns={ 'date_of_join' :fields.date('Date of Join',required=True), 'current_date':fields.date('Applied date',require=True), 'eligible_details':fields.char('Eligibility Details'), 'visaexpiry_date':fields.date('Visa Expiry Date'), 'residence_expiry_date':fields.date('Residence Expiry'), 'work_permit_date':fields.date('Work Permit'), 'insurance_expiry_date':fields.date('Insurance date'), 'license_date':fields.date('Insurance date') } def check_eligibility(self,cr,uid,ids,context=None): day_obj=self.read(cr,uid,ids,['date_of_join','current_date'],context=context) calc_vacation=self.pool.get('scheme.type.info').read(cr,uid,ids,['interval','criteria','scheme_id'],context=context) dateformat="%Y-%m-%d" d1=datetime.strptime(day_obj[0]['date_of_join'],dateformat) d2=datetime.strptime(day_obj[0]['current_date'],dateformat) v1=d2-d1 total_days=v1.days if total_days182 # # eligible for 2 ticket and 50000 # # if working hr employee inheritedhr.employee <xpath expr=" /form/sheet/notebook/page/group/group/field[@name='active' ]" position="after"> <xpath expr="/form/sheet/notebook/page[@string='HR Settings']" position="after"> <xpath expr=" /form/sheet/notebook/page[2]/group/group[4]/field[@name='birthday']" position="before"> scheme.type.info.treescheme.type.infoscheme.type.info.formscheme.type.info Vacation Detailsscheme.type.infoformtree,form

Odoo
on 6/10/14, 6:04 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/10/14, 4:37 AM
Seen: 798 times
Last updated: 3/16/15, 8:10 AM