冷加工的合格率单独处理

This commit is contained in:
caoqianming 2022-01-20 13:50:30 +08:00
parent 0c5601f53a
commit 7f4da0221c
4 changed files with 28 additions and 8 deletions

View File

@ -2,13 +2,14 @@ from django.db.models import base
from rest_framework import urlpatterns from rest_framework import urlpatterns
from django.urls import path, include from django.urls import path, include
from rest_framework.routers import DefaultRouter from rest_framework.routers import DefaultRouter
from apps.develop.views import CleanDataView, UpdateCuttingView, UpdateFIFOItem, UpdateLastTestResult from apps.develop.views import CleanDataView, UpdateCuttingView, UpdateFIFOItem, UpdateLastTestResult, UpdateSpg
urlpatterns = [ urlpatterns = [
path('cleandata/', CleanDataView.as_view()), path('cleandata/', CleanDataView.as_view()),
path('update_cutting/', UpdateCuttingView.as_view()), path('update_cutting/', UpdateCuttingView.as_view()),
path('update_last_result/', UpdateLastTestResult.as_view()), path('update_last_result/', UpdateLastTestResult.as_view()),
path('update_last_result/', UpdateLastTestResult.as_view()), path('update_last_result/', UpdateLastTestResult.as_view()),
path('update_fifoitem/', UpdateFIFOItem.as_view()) path('update_fifoitem/', UpdateFIFOItem.as_view()),
path('update_spg/', UpdateSpg.as_view())
] ]

View File

@ -6,7 +6,7 @@ from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response from rest_framework.response import Response
from apps.inm.models import FIFO, FIFOItem, Inventory, MaterialBatch from apps.inm.models import FIFO, FIFOItem, Inventory, MaterialBatch
from apps.mtm.models import Material from apps.mtm.models import Material
from apps.pm.models import ProductionPlan from apps.pm.models import ProductionPlan, SubProductionPlan
from apps.sam.models import Order from apps.sam.models import Order
from apps.wf.models import Ticket from apps.wf.models import Ticket
from apps.wpm.models import Operation, OperationMaterial, WProduct, WproductFlow from apps.wpm.models import Operation, OperationMaterial, WProduct, WproductFlow
@ -80,3 +80,14 @@ class UpdateFIFOItem(APIView):
i.is_testok = None i.is_testok = None
i.save() i.save()
return Response() return Response()
class UpdateSpg(APIView):
permission_classes = [IsAdminUser]
@transaction.atomic
def post(self, request, format=None):
"""
冷加工重新计算合格率
"""
for i in SubProductionPlan.objects.filter(subproduction__process__id=1):
WpmServies.update_subproduction_progress_main(sp=i)
return Response()

View File

@ -40,7 +40,13 @@ class ProcessYieldView(CreateAPIView):
# 根据产品日志记录进行聚合 # 根据产品日志记录进行聚合
count_ok_g = list(wpfs.filter(act_state__in=[WProduct.WPR_ACT_STATE_INM, count_ok_g = list(wpfs.filter(act_state__in=[WProduct.WPR_ACT_STATE_INM,
WProduct.WPR_ACT_STATE_OK, WProduct.WPR_ACT_STATE_SELLED]).values('step__process__id').annotate(count_ok=Count('id'))) WProduct.WPR_ACT_STATE_OK, WProduct.WPR_ACT_STATE_SELLED]).values('step__process__id').annotate(count_ok=Count('id')))
count_notok_g = list(wpfs.filter(act_state__in=[WProduct.WPR_ACT_STATE_NOTOK, WProduct.WPR_ACT_STATE_SCRAP]).values('step__process__id', count_notok_g = list(
(
wpfs.filter(act_state__in=[WProduct.WPR_ACT_STATE_NOTOK, WProduct.WPR_ACT_STATE_SCRAP]).exclude(step__process__id=1)
| wpfs.filter(act_state__in=[WProduct.WPR_ACT_STATE_NOTOK, WProduct.WPR_ACT_STATE_SCRAP],
step__process__id=1).exclude(number=None)
)\
.values('step__process__id',
).annotate(count_notok=Count('id'))) ).annotate(count_notok=Count('id')))
ret = [] ret = []
process_l = list(Process.objects.filter(is_deleted=False).order_by('number').values('id', 'name')) process_l = list(Process.objects.filter(is_deleted=False).order_by('number').values('id', 'name'))
@ -50,9 +56,7 @@ class ProcessYieldView(CreateAPIView):
if m['step__process__id'] == ret_item['id']: if m['step__process__id'] == ret_item['id']:
ret_item['count_ok'] = m['count_ok'] ret_item['count_ok'] = m['count_ok']
for n in count_notok_g: for n in count_notok_g:
if n['step__process__id'] == 1: # 如果是冷加工 if n['step__process__id'] == ret_item['id']:
ret['count_notok'] = ret_item['count_ok']
elif n['step__process__id'] == ret_item['id']:
ret_item['count_notok'] = n['count_notok'] ret_item['count_notok'] = n['count_notok']
rate = (ret_item['count_ok']/(ret_item['count_ok']+ret_item['count_notok'])) \ rate = (ret_item['count_ok']/(ret_item['count_ok']+ret_item['count_notok'])) \
if ret_item['count_ok']+ret_item['count_notok']>0 else 1 if ret_item['count_ok']+ret_item['count_notok']>0 else 1

View File

@ -114,7 +114,11 @@ class WpmServies(object):
objs = WproductFlow.objects.filter(subproduction_plan=sp, is_lastlog=True) objs = WproductFlow.objects.filter(subproduction_plan=sp, is_lastlog=True)
count_ok = objs.filter(act_state__in=[WProduct.WPR_ACT_STATE_INM, count_ok = objs.filter(act_state__in=[WProduct.WPR_ACT_STATE_INM,
WProduct.WPR_ACT_STATE_OK, WProduct.WPR_ACT_STATE_SELLED]).count() WProduct.WPR_ACT_STATE_OK, WProduct.WPR_ACT_STATE_SELLED]).count()
count_notok = objs.filter(act_state__in=[WProduct.WPR_ACT_STATE_NOTOK, WProduct.WPR_ACT_STATE_SCRAP]).count() count_notok = (
objs.filter(act_state__in=[WProduct.WPR_ACT_STATE_NOTOK, WProduct.WPR_ACT_STATE_SCRAP]).exclude(step__process__id=1)
| objs.filter(act_state__in=[WProduct.WPR_ACT_STATE_NOTOK, WProduct.WPR_ACT_STATE_SCRAP],
step__process__id=1).exclude(number=None)
).count()
count_real = objs.exclude(act_state__in=[WProduct.WPR_ACT_STATE_TORETEST, count_real = objs.exclude(act_state__in=[WProduct.WPR_ACT_STATE_TORETEST,
WProduct.WPR_ACT_STATE_DOWAIT, WProduct.WPR_ACT_STATE_DOING]).count() WProduct.WPR_ACT_STATE_DOWAIT, WProduct.WPR_ACT_STATE_DOING]).count()
ins = SubProductionProgress.objects.filter(subproduction_plan=sp, ins = SubProductionProgress.objects.filter(subproduction_plan=sp,