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

Why loop if condition message is not working inside for loop need a help----------

By
Odoo
on 6/17/14, 7:10 AM 382 views

Here I attached my code ,then

 

class hr_contract(osv.osv):

     _inherit='hr.contract'

     _columns={
              'date_of_join' :fields.date('Date of Join',required=True),
              'current_date':fields.date('Applied date',required=True),
              'eligible_details':fields.char('Eligibility Details'),
             }
     
     def  check_eligibility(self,cr,uid,ids,context=None):
         msg=""
         if ids:
             day_obj=self.read(cr,uid,ids,['date_of_join','current_date'],context=context)
             scheme_ids = self.pool.get('scheme.type.info').search(cr, uid, [], context=context)
             calc_vacation=self.pool.get('scheme.type.info').read(cr,uid,scheme_ids,['interval','criteria','interval1'],context=context)
             
             print "day_obj####################",day_obj
             print "scheme_ids################",scheme_ids
             print "calc_vacation#######################",calc_vacation
             
             
             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
             print "total_days",total_days
             
             for cal_val in calc_vacation:
                 print "inside for loop cal_val ###############",cal_val
                 interval = cal_val['interval']
                 print "###################Interval", interval
                 if total_days in range(cal_val['interval'],cal_val['interval1']):
                     print "###################Inside if %%%%%%%%%%%%%%%%%%", total_days
                     print "###################cal_val['interval'] %%%%%%%%%%%%%%%%%%", cal_val['interval']
                     print "###################cal_val['interval1'] %%%%%%%%%%%%%%%%%%", cal_val['interval1']
                     msg=cal_val['criteria']
                 else:
                        msg="You are not Eligible"
             vals={
                   'eligible_details':msg
                   }
             self.write(cr,uid,ids,vals)
        
         return True
     
     

hr_contract()

the code of  

if total_days in range(cal_val['interval'],cal_val['interval1']): is excecuted but not printed from the master table  its condition from the above code  ie.

msg=cal_val['criteria']  #This statement is not printing..

it will go directly to else condition for every comaprison why?

 

0

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 6/18/14, 3:02 AM

Try the below code:-

def check_eligibility(self,cr,uid,ids,context=None):
         msg=""
         if ids:
             day_obj=self.read(cr,uid,ids,['date_of_join','current_date'],context=context)
             scheme_ids = self.pool.get('scheme.type.info').search(cr, uid, [], context=context)
             calc_vacation=self.pool.get('scheme.type.info').read(cr,uid,scheme_ids,['interval','criteria','interval1'],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
             for cal_val in calc_vacation:
                 interval = cal_val['interval']
                 if total_days in range(cal_val['interval'],cal_val['interval1']):
                     msg=cal_val['criteria']                
             if not msg:           
                msg="You are not Eligible"
             vals={
                   'eligible_details':msg
                   }
             self.write(cr,uid,ids,vals)        
         return True

Thanks Prakash,......for your help..

Odoo
on 6/18/14, 12:10 PM

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/17/14, 7:10 AM
Seen: 382 times
Last updated: 3/16/15, 8:10 AM