29 lines
		
	
	
		
			993 B
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			993 B
		
	
	
	
		
			Python
		
	
	
	
| # Create your tasks here
 | |
| from __future__ import absolute_import, unicode_literals
 | |
| from apps.rpm.models import Rpj
 | |
| from apps.utils.tasks import CustomTask
 | |
| from celery import shared_task
 | |
| from django.utils import timezone
 | |
| 
 | |
| 
 | |
| @shared_task(base=CustomTask)
 | |
| def close_rpj_by_leave_time():
 | |
|     """
 | |
|     定时关闭相关方入厂项目
 | |
|     """
 | |
|     now = timezone.now()
 | |
|     # 正常结束/其他关闭
 | |
|     rpjs = Rpj.objects.filter(leave_time__lt=now).exclude(state__in=[Rpj.RPJ_DONE, Rpj.RPJ_CLOSE])
 | |
|     for i in rpjs:
 | |
|         if i.state == Rpj.RPJ_WORKING:
 | |
|             i.state = Rpj.RPJ_DONE
 | |
|             i.save()
 | |
|         else:
 | |
|             i.state = Rpj.RPJ_CLOSE
 | |
|             i.save()
 | |
|             # 工单审批如果还未结束,直接关闭
 | |
|             from apps.wf.models import Ticket
 | |
|             from apps.wf.services import WfService
 | |
|             if i.ticket and i.ticket.state != Ticket.TICKET_ACT_STATE_FINISH:
 | |
|                 WfService.close_by_task(i.ticket, '相关方入厂时间到期')
 |