50 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
	
| from django.db import transaction
 | |
| from django.shortcuts import render
 | |
| from rest_framework.decorators import permission_classes
 | |
| from rest_framework.views import APIView
 | |
| from rest_framework.permissions import IsAdminUser
 | |
| from rest_framework.response import Response
 | |
| from apps.inm.models import FIFO, Inventory, MaterialBatch
 | |
| from apps.mtm.models import Material
 | |
| from apps.pm.models import ProductionPlan
 | |
| from apps.sam.models import Order
 | |
| from apps.wf.models import Ticket
 | |
| from apps.wpm.models import Operation, OperationMaterial, WProduct, WproductFlow
 | |
| from apps.wpm.services import WpmServies
 | |
| # Create your views here.
 | |
| 
 | |
| class CleanDataView(APIView):
 | |
|     permission_classes = [IsAdminUser]
 | |
| 
 | |
|     def post(self, request, format=None):
 | |
|         """
 | |
|         清空数据库
 | |
|         """
 | |
|         Order.objects.all().delete(soft=False)
 | |
|         ProductionPlan.objects.all().delete(soft=False)
 | |
|         FIFO.objects.all().delete(soft=False)
 | |
|         Material.objects.filter(type__in=[Material.MA_TYPE_GOOD, Material.MA_TYPE_HALFGOOD]).update(count=0)
 | |
|         MaterialBatch.objects.filter(material__type__in=[Material.MA_TYPE_GOOD, Material.MA_TYPE_HALFGOOD]).delete()
 | |
|         Inventory.objects.filter(material__type__in=[Material.MA_TYPE_GOOD, Material.MA_TYPE_HALFGOOD]).delete()
 | |
|         Ticket.objects.all().delete(soft=False)
 | |
|         Operation.objects.all().delete()
 | |
|         return Response()
 | |
| 
 | |
| 
 | |
| class UpdateCuttingView(APIView):
 | |
|     permission_classes = [IsAdminUser]
 | |
|     @transaction.atomic
 | |
|     def post(self, request, format=None):
 | |
|         """
 | |
|         更新下料清单
 | |
|         """
 | |
|         for i in WProduct.objects.all():
 | |
|             sp = WproductFlow.objects.filter(wproduct=i).order_by('id').first().subproduction_plan
 | |
|             op_q = OperationMaterial.objects.filter(subproduction_plan=sp, operation__step__id=1, operation__is_submited=True)
 | |
|             op = op_q.first().operation
 | |
|             i.coperation = op
 | |
|             i.save()
 | |
|             WproductFlow.objects.filter(wproduct=i).update(coperation=op)
 | |
|             WpmServies.update_cutting_list_with_operation(op)
 | |
|         return Response()
 |