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

Variable returns empty list and i cannot read values from an another model like "scheme.type.info"

By
Odoo
on 6/16/14, 2:27 AM 786 views


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

class hr_employee(osv.osv):

     _inherit='hr.employee'
 

     _columns={
              'date_of_join' :fields.date('Date of Join',required=True),
              'current_date':fields.date('Applied date',require=True),
         
                             }
     def  check_eligibility(self,cr,uid,ids,context=None):
         if ids:
             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)      # 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
             if calc_vacation:  
                 print "Inside calc vacation"
                 if total_days <=calc_vacation[0]['interval']:
                    msg=calc_vacation[0]['criteria']

             else:
                 raise osv.orm.except_orm('Error','Unable to continue, please provide Vacation Details')  
             vals={
                   'eligible_details':msg
                   }
             self.write(cr,uid,ids,vals)
        
         return True

    
     
hr_employee()
     
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()
     
     
**********************************************************************************

day_obj############################# [{'current_date': '2014-06-24', 'date_of_join': '2014-03-01', 'id': 1, 'resource_id': 1}]

  1. calc_vacation## []

 

     

 

   

0

Prakash

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

OpenERP Devloper at SunARC Technology

Prakash
On 6/16/14, 2:42 AM

To pass the scheme.type.info ids value.

Try the below code,

             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','scheme_id'],context=context)    

        Edit:-

           if not day_obj or not day_obj[0]['date_of_join']:
                return False

          if not  calc_vacation or not  calc_vacation[0]['interval']:
                return False

Hi Prakash, I change the code...............like def check_eligibility(self,cr,uid,ids,context=None): 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) print "scheme_ids##################",scheme_ids calc_vacation=self.pool.get('scheme.type.info').read(cr,uid,scheme_ids,['interval','criteria','scheme_id'],context=context) 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 if total_days

Odoo
on 6/16/14, 3:31 AM

Error is coming like---------------- if total_days

Odoo
on 6/16/14, 3:33 AM

Thanks...Prakash its working almost .. need fix some more points

Odoo
on 6/16/14, 8:17 AM
0

Odoo

--Odoo --
1328
| 5 2 5
kerala, India
--Odoo --

Working as a Odoo Functional and Technical Expert

Odoo
On 6/16/14, 8:14 AM

updated answer pls check add condition and check array value is present or not.

Odoo
on 6/16/14, 8:14 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/16/14, 2:27 AM
Seen: 786 times
Last updated: 3/16/15, 8:10 AM