From 004030e9dfbf07080840bd00002667cf346b12ab Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 28 Dec 2021 15:37:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E4=BA=A7=E5=93=81=E5=8F=98?= =?UTF-8?q?=E5=8A=A8=E6=97=A5=E5=BF=97=E6=9B=B4=E6=96=B0=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/wpm/services.py | 35 +++++++++++++++++----------------- hb_server/apps/wpm/signals.py | 7 ++----- hb_server/apps/wpm/views.py | 27 ++++++++++++++++---------- 3 files changed, 36 insertions(+), 33 deletions(-) diff --git a/hb_server/apps/wpm/services.py b/hb_server/apps/wpm/services.py index 230b2e5..c51e08a 100644 --- a/hb_server/apps/wpm/services.py +++ b/hb_server/apps/wpm/services.py @@ -5,7 +5,7 @@ from apps.pm.models import SubProductionPlan, SubProductionProgress from apps.mtm.models import Material, Step, SubprodctionMaterial from apps.qm.models import TestRecord from apps.system.models import User -from apps.wpm.models import WProduct, WprouctTicket +from apps.wpm.models import WProduct, WproductFlow, WprouctTicket from utils.tools import ranstr class WpmServies(object): @@ -61,11 +61,8 @@ class WpmServies(object): wt = WprouctTicket.objects.order_by('id').last() #取最后的工单 if wt.step.process == test.step.process: wproduct.ng_sign = None - # 更新子计划合格进度 - ins = SubProductionProgress.objects.get(subproduction_plan=wproduct.subproduction_plan, - is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT) - ins.count_ok = ins.count_ok + 1 - ins.save() + # 更新子计划相关进度 + cls.update_subproduction_progress_main(sp=wproduct.subproduction_plan) else:# 如果不合格 wproduct.act_state = WProduct.WPR_ACT_STATE_NOTOK # 需要走不合格品审理的工单 @@ -73,16 +70,18 @@ class WpmServies(object): wproduct.test = None wproduct.save() -@classmethod -def update_subproduction_progress_main(cls, sp:SubProductionPlan, is_workdone:bool=False, is_testok:bool=False): - """ - 更新生产进度 - """ - if is_testok: + @classmethod + def update_subproduction_progress_main(cls, sp:SubProductionPlan): + """ + 根据产品变动日志更新生产进度 + """ + objs = WproductFlow.objects.filter(subporduction_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_real = objs.exclude(act_state__in=[WProduct.WPR_ACT_STATE_TORETEST, + WProduct.WPR_ACT_STATE_DOWAIT, WProduct.WPR_ACT_STATE_DOING]) ins = SubProductionProgress.objects.get(subproduction_plan=sp, - is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT) - # 该计划下的所有产品 - wps = WProduct.objects.filter(subproduction_plan=sp) - if is_workdone: - ins = SubProductionProgress.objects.get(subproduction_plan=sp, - is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT) \ No newline at end of file + is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT) + ins.count_ok = count_ok + ins.count_real = count_real + ins.save() \ No newline at end of file diff --git a/hb_server/apps/wpm/signals.py b/hb_server/apps/wpm/signals.py index 48b7b3c..4c936b8 100644 --- a/hb_server/apps/wpm/signals.py +++ b/hb_server/apps/wpm/signals.py @@ -8,6 +8,7 @@ from django.dispatch import receiver from rest_framework import exceptions from apps.wpm.models import WProduct, WproductFlow, WprouctTicket from apps.wpm.models import OperationWproduct +from apps.wpm.services import WpmServies @receiver(post_save, sender=Ticket) @@ -69,11 +70,7 @@ def handleTicket(sender, instance, created, **kwargs): wp.act_state = WProduct.WPR_ACT_STATE_DOWAIT wp.save() # 更新子计划合格进度 - if sp != wt.subproduction_plan: - ins = SubProductionProgress.objects.get(subproduction_plan=sp, - is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT) - ins.count_ok = ins.count_ok - 1 - ins.save() + WpmServies.update_subproduction_progress_main(sp=sp) else: raise exceptions.APIException('返回步骤点错误') diff --git a/hb_server/apps/wpm/views.py b/hb_server/apps/wpm/views.py index a3b840c..a83db3c 100644 --- a/hb_server/apps/wpm/views.py +++ b/hb_server/apps/wpm/views.py @@ -180,13 +180,19 @@ class WProductViewSet(ListModelMixin, GenericViewSet): 半成品 """ perms_map={'*':'*'} - queryset = WProduct.objects.select_related('step', 'material', 'subproduction_plan').filter(is_hidden=False) + queryset = WProduct.objects.select_related('step', 'material', 'subproduction_plan') serializer_class = WProductListSerializer filterset_class = WProductFilterSet search_fields = ['number'] ordering_fields = ['id'] ordering = ['id'] + def get_queryset(self): + queryset = self.queryset + if self.request.query_params.get('tag', None) != 'show_hidden': + queryset = queryset.filter(is_hidden=False) + return queryset + @action(methods=['post'], detail=False, perms_map={'post':'*'}, serializer_class=WpmTestFormInitSerializer) def test_init(self, request, pk=None): """ @@ -283,7 +289,12 @@ class WProductViewSet(ListModelMixin, GenericViewSet): FIFOItemProduct.objects.bulk_create(ips) # 更新库存并修改半成品进行状态 update_inm(fifo) - wproducts.update(act_state=WProduct.WPR_ACT_STATE_INM, warehouse=warehouse, update_by=request.user, update_time=timezone.now()) + for i in wproducts: + i.act_state = WProduct.WPR_ACT_STATE_INM + i.warehouse = warehouse + i.update_by = request.user + i.update_time = timezone.now() + i.save() return Response() @action(methods=['post'], detail=True, perms_map={'post':'*'}, serializer_class=WproductPutInSerializer) @@ -544,10 +555,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd # 更新子计划生产进度 # 如果产品有返工标记不做计算 if wp.ng_sign not in [WProduct.NG_BACK_FIX, WProduct.NG_BACK_WORK]: - ins = SubProductionProgress.objects.get(subproduction_plan=wsp, - is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT) - ins.count_real = ins.count_real + 1 - ins.save() + WpmServies.update_subproduction_progress_main(sp=wsp) wp.operation = None wp.update_by = request.user wp.save() @@ -560,7 +568,8 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd act_state=WProduct.WPR_ACT_STATE_DOWAIT, remark='', subproduction_plan=i.subproduction_plan) for x in range(i.count): - WProduct.objects.create(**wpr) + WProduct.objects.create(**wpr) + WpmServies.update_subproduction_progress_main(sp=i.subproduction_plan) elif step.type == Step.STEP_TYPE_COMB: oms_w = OperationMaterial.objects.filter(operation=op, type=SubprodctionMaterial.SUB_MA_TYPE_OUT, subproduction_progress__is_main=True) @@ -577,9 +586,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd else: wproduct.act_state = WProduct.WPR_ACT_STATE_TOTEST # 更新子计划进度 - instance = oms_w.subproduction_progress - instance.count_real = instance.count_real + 1 # 这个地方可能会有问题,不够严谨 - instance.save() + WpmServies.update_subproduction_progress_main(sp=oms_w.subproduction_plan) wproduct.create_by = request.user wproduct.save() # 隐藏原半成品