2016-08-15 42 views
0

我尝试使用Openerp调度程序执行功能,但它没有任何改变。如果我只运行这个函数,它可以很好地工作,但不能和调度器一起工作。请帮我解决一下这个。Openerp Scheduler正在运行,但附加功能未执行

在我加入这个hr_holidays.xml文件,

<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> 

,几乎没有调整的UI看起来是这样的; enter image description here

enter image description here

enter image description here

功能

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 
+0

T1值是你crons运行? – CZoellner

+0

你能告诉我们这个功能吗?并确保在该cron正在运行时日志中没有错误。 –

+0

现在上传了函数 –

回答

1

你只需要为参数,无需通过cron通过它设置默认值,如果在需要函数从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 

如果它是强制性的,那么你需要从cron的传递ARGS

enter image description here

+0

不,仍然不能正常工作 –

+0

即使我按照上面的步骤执行了调度程序,因为它的时间发生了变化,但在调度程序中定义的方法不会运行。 –

+0

您可以设置断点到方法中,并在1分钟后设置调度程序,并检查控制是否在方法中出现? –