From 7f4da0221ca8d4b10bae85e8cdaee09bbc6ba0fa Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 20 Jan 2022 13:50:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=B7=E5=8A=A0=E5=B7=A5=E7=9A=84=E5=90=88?= =?UTF-8?q?=E6=A0=BC=E7=8E=87=E5=8D=95=E7=8B=AC=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/develop/urls.py | 5 +++-- hb_server/apps/develop/views.py | 13 ++++++++++++- hb_server/apps/srm/views.py | 12 ++++++++---- hb_server/apps/wpm/services.py | 6 +++++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/hb_server/apps/develop/urls.py b/hb_server/apps/develop/urls.py index b284243..79f8f04 100644 --- a/hb_server/apps/develop/urls.py +++ b/hb_server/apps/develop/urls.py @@ -2,13 +2,14 @@ from django.db.models import base from rest_framework import urlpatterns from django.urls import path, include 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 = [ path('cleandata/', CleanDataView.as_view()), path('update_cutting/', UpdateCuttingView.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()) ] diff --git a/hb_server/apps/develop/views.py b/hb_server/apps/develop/views.py index f02f55f..f6a52fc 100644 --- a/hb_server/apps/develop/views.py +++ b/hb_server/apps/develop/views.py @@ -6,7 +6,7 @@ from rest_framework.permissions import IsAdminUser from rest_framework.response import Response from apps.inm.models import FIFO, FIFOItem, Inventory, MaterialBatch 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.wf.models import Ticket from apps.wpm.models import Operation, OperationMaterial, WProduct, WproductFlow @@ -80,3 +80,14 @@ class UpdateFIFOItem(APIView): i.is_testok = None i.save() 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() diff --git a/hb_server/apps/srm/views.py b/hb_server/apps/srm/views.py index b5a7158..ec7a398 100644 --- a/hb_server/apps/srm/views.py +++ b/hb_server/apps/srm/views.py @@ -40,7 +40,13 @@ class ProcessYieldView(CreateAPIView): # 根据产品日志记录进行聚合 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'))) - 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'))) ret = [] 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']: ret_item['count_ok'] = m['count_ok'] for n in count_notok_g: - if n['step__process__id'] == 1: # 如果是冷加工 - ret['count_notok'] = ret_item['count_ok'] - elif n['step__process__id'] == ret_item['id']: + if n['step__process__id'] == ret_item['id']: ret_item['count_notok'] = n['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 diff --git a/hb_server/apps/wpm/services.py b/hb_server/apps/wpm/services.py index 76a585d..d880f7f 100644 --- a/hb_server/apps/wpm/services.py +++ b/hb_server/apps/wpm/services.py @@ -114,7 +114,11 @@ class WpmServies(object): objs = WproductFlow.objects.filter(subproduction_plan=sp, is_lastlog=True) count_ok = objs.filter(act_state__in=[WProduct.WPR_ACT_STATE_INM, 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, WProduct.WPR_ACT_STATE_DOWAIT, WProduct.WPR_ACT_STATE_DOING]).count() ins = SubProductionProgress.objects.filter(subproduction_plan=sp,