Swan White
Swan White

Reputation: 211

Openerp Scheduler is working but the attached funciton not executing

I tried to execute a function using Openerp scheduler but it changed nothing. If I run the function only it works perfectly fine but not with the scheduler. Please help me with this.

in hr_holidays.xml file I added this,

<record id="ir_cron_scheduler" model="ir.cron">
  <field name="name">Casual Leave Allocation</field>
  <field name="interval_number">1</field>
  <field name="interval_type">minutes</field>
  <field name="numbercall">-1</field>
  <field eval="False" name="doall"/>
  <field eval="'hr.holidays'" name="hr.holidays"/>
  <field eval="'allocate_on_probations'" name="allocate_on_probations"/>
  <field eval="'()'" name="args"/>
</record>

and with little adjustments UI looks like this; enter image description here

enter image description here

enter image description here

The function

def allocate_on_probations(self, cr, uid, ids,tl, context=None):
    allo=0
    state='active'
    result = {}

    emps=self.pool.get('hr.employee').search(cr, uid, [('current_status','=','active')], context=context)
    if emps:    
        for r in emps:
            hol_state=2 
            gt_dt=cr.execute("""SELECT appointed_date FROM hr_employee WHERE id= %d order by id"""%(r))
            gt_dd=cr.fetchone()[0]

            #getting today details
            today = datetime.datetime.now()
            tt=today.date()
            td=tt.day
            tm=tt.month
            ty=tt.year

            #getting appointment date details
            app=datetime.datetime.strptime(gt_dd, "%Y-%m-%d").date()
            #print app
            ay=app.year
            am=app.month
            ad=app.day

            if ay==ty:
                #compairing today and appointed date
                comp=(tt-app)
                chat=int(comp.days)
                chat_mod=chat%30
                print chat_mod
                print r

                if chat_mod==29:
                    hol_obj=self.pool.get('hr.holidays')
                    print hol_obj
                    condition_1=[('employee_id','=',r),('type','=','add'),('holiday_status_id','=',hol_state)]
                    hol_emp=hol_obj.search(cr, uid,condition_1, context=context)

                    if hol_emp:                
                        for n in hol_emp:
                            hol_dt=cr.execute("""SELECT number_of_days_temp FROM hr_holidays WHERE id= %d order by id"""%(n))
                            hol_dd=cr.fetchone()[0]
                            hol_inc=(hol_dd+0.5)

                            print hol_inc
                            cr.execute("""UPDATE hr_holidays SET number_of_days_temp= %d WHERE id= %d"""%(hol_inc,n))
                            cr.execute("""UPDATE hr_holidays SET number_of_days= %d  WHERE id= %d"""%(hol_inc,n))

    return True

Upvotes: 0

Views: 108

Answers (1)

You just need to set default value for that parameter and no need to pass it via cron, and if it is required in function the pass it from the cron.

def allocate_on_probations(self, cr, uid, ids,tl=False, context=None):

        allo=0
        state='active'
        result = {}


        emps=self.pool.get('hr.employee').search(cr, uid, [('current_status','=','active')], context=context)
        if emps:

            for r in emps:
                hol_state=2 
                gt_dt=cr.execute("""SELECT appointed_date FROM hr_employee WHERE id= %d order by id"""%(r))
                gt_dd=cr.fetchone()[0]

                #getting today details
                today = datetime.datetime.now()
                tt=today.date()
                td=tt.day
                tm=tt.month
                ty=tt.year

                #getting appointment date details
                app=datetime.datetime.strptime(gt_dd, "%Y-%m-%d").date()
                #print app
                ay=app.year
                am=app.month
                ad=app.day

                if ay==ty:
                    #compairing today and appointed date
                    comp=(tt-app)
                    chat=int(comp.days)
                    chat_mod=chat%30
                    print chat_mod
                    print r

                    if chat_mod==29:
                        hol_obj=self.pool.get('hr.holidays')
                        print hol_obj
                        condition_1=[('employee_id','=',r),('type','=','add'),('holiday_status_id','=',hol_state)]
                        hol_emp=hol_obj.search(cr, uid,condition_1, context=context)

                        if hol_emp:

                            for n in hol_emp:
                                hol_dt=cr.execute("""SELECT number_of_days_temp FROM hr_holidays WHERE id= %d order by id"""%(n))
                                hol_dd=cr.fetchone()[0]
                                hol_inc=(hol_dd+0.5)

                                print hol_inc
                                cr.execute("""UPDATE hr_holidays SET number_of_days_temp= %d WHERE id= %d"""%(hol_inc,n))
                                cr.execute("""UPDATE hr_holidays SET number_of_days= %d  WHERE id= %d"""%(hol_inc,n))




        return True

And if it is mandatory then you need to pass t1 value from the cron in args

enter image description here

Upvotes: 1

Related Questions