2016-08-15 81 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分鐘後設置調度程序,並檢查控制是否在方法中出現? –