From f2af3e4a8d0b872845e3606ee74fc393806ab0dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E5=89=8D=E6=98=8E?= <909355014@qq.com> Date: Tue, 28 Jun 2022 16:58:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=90=E5=B7=A5=E5=BA=8F=E6=A3=80=E6=9F=A5bu?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/wpm/models.py | 7 ++++ hb_server/apps/wpm/services.py | 43 +++++++++++++++------ hb_server/apps/wpm/views.py | 70 +++++++++++++++++----------------- 3 files changed, 72 insertions(+), 48 deletions(-) diff --git a/hb_server/apps/wpm/models.py b/hb_server/apps/wpm/models.py index 085a20d..a78c6ee 100644 --- a/hb_server/apps/wpm/models.py +++ b/hb_server/apps/wpm/models.py @@ -136,6 +136,13 @@ class WProduct(CommonAModel): """ return self.test_wproduct.filter(type=TestRecord.TEST_PROCESS, is_submited=True).order_by('-id').first() + @property + def last_wp_test(self): + """ + 最后提交的本产品自检 + """ + return self.test_wproduct.filter(is_submited=True).order_by('-id').first() + class WprouctTicket(CommonAModel): """ diff --git a/hb_server/apps/wpm/services.py b/hb_server/apps/wpm/services.py index 42de513..081553e 100644 --- a/hb_server/apps/wpm/services.py +++ b/hb_server/apps/wpm/services.py @@ -3,7 +3,7 @@ from typing import List from django.db.models.expressions import F from apps.pm.models import ProductionPlan, SubProductionPlan, SubProductionProgress -from apps.mtm.models import Material, Step, SubprodctionMaterial +from apps.mtm.models import Material, Step, SubprodctionMaterial, UsedStep from apps.qm.models import TestRecord from apps.system.models import User from apps.wf.models import State, TicketFlow, Transition @@ -13,19 +13,38 @@ from rest_framework.exceptions import ParseError class WpmService(object): @classmethod - def get_next_step(cls, subproduction_plan:SubProductionPlan, nowstep:Step): + def get_step_info(cls, subproduction_plan:SubProductionPlan, nowstep:Step, get_next=True): """ - 获取下一步骤的信息 + 获取本步骤或下一步骤的信息 """ - steps_list = subproduction_plan.steps - stepIds = [i['id'] for i in steps_list] - pindex = stepIds.index(nowstep.id) - need_test = steps_list[pindex].get('need_test', False) - reuse_form = steps_list[pindex].get('reuse_form', True) - if pindex + 1 < len(stepIds): - return Step.objects.get(pk=stepIds[pindex+1]), need_test, reuse_form - else: - return nowstep, need_test, reuse_form + used_steps = UsedStep.objects.filter(subproduction=subproduction_plan.subproduction).order_by('step__number') + for index, i in enumerate(used_steps): + if i.step == nowstep and get_next: + try: + used_step = used_steps[index+1] + return used_step, used_step.need_test, used_step.reuse_form + except: + return nowstep, i.need_test, i.reuse_form + elif i.step == nowstep and get_next == False: + return nowstep, i.need_test, i.reuse_form + + # steps_list = subproduction_plan.steps + # stepIds = [i['id'] for i in steps_list] + # pindex = stepIds.index(nowstep.id) + # if get_next: + # if pindex + 1 < len(stepIds): + # pindex = pindex + 1 + # need_test = steps_list[pindex].get('need_test', False) + # reuse_form = steps_list[pindex].get('reuse_form', True) + # return Step.objects.get(pk=stepIds[pindex]), need_test, reuse_form + # else: + # need_test = steps_list[pindex].get('need_test', False) + # reuse_form = steps_list[pindex].get('reuse_form', True) + # return nowstep, need_test, reuse_form + # else: + # need_test = steps_list[pindex].get('need_test', False) + # reuse_form = steps_list[pindex].get('reuse_form', True) + # return @classmethod def get_subplans_queryset_from_wproducts(cls, wproducts:List): diff --git a/hb_server/apps/wpm/views.py b/hb_server/apps/wpm/views.py index 80fee33..d448544 100644 --- a/hb_server/apps/wpm/views.py +++ b/hb_server/apps/wpm/views.py @@ -213,8 +213,8 @@ class WProductViewSet(ListModelMixin, RetrieveModelMixin, GenericViewSet): elif wproduct.act_state == WProduct.WPR_ACT_STATE_TOCOMBTEST: savedict['type'] = TestRecord.TEST_COMB elif wproduct.act_state == WProduct.WPR_ACT_STATE_TOTEST: - _, need_test, _ = WpmService.get_next_step(wproduct.subproduction_plan, wproduct.step) - if need_test: + step, need_test, _ = WpmService.get_step_info(wproduct.subproduction_plan, wproduct.step, get_next=False) + if need_test and wproduct.step != step: savedict['is_midtesting'] = True # if UsedStep.objects.filter(subproduction=wproduct.subproduction_plan.subproduction).first().need_test: tr = TestRecord.objects.create(**savedict) @@ -700,32 +700,31 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd wsp = i.subproduction_plan # 获取下一步子工序 - newstep, needTest, reuseForm = WpmService.get_next_step(wsp, step) + newstep, needTest, reuseForm = WpmService.get_step_info(wsp, step) wp.step = newstep wp.pre_step = step wp.material = wsp.product if step == newstep: wp.act_state = WProduct.WPR_ACT_STATE_TOTEST - if wp.test:# 如果有正在进行的工序中检验 - if reuseForm: - wp.test.is_midtesting = False - wp.test.is_submited = False - wp.test.save() - else: - wp.test = None - wp.save() + last_test = wp.last_wp_test + if last_test and reuseForm: + last_test.is_midtesting = False + last_test.is_submited = False + last_test.save() + wp.test = last_test + wp.save() else: wp.act_state = WProduct.WPR_ACT_STATE_DOWAIT - if needTest: #子工序若需要检验 + if needTest: #子工序若需要检验 wp.act_state = WProduct.WPR_ACT_STATE_TOTEST - if wp.test:# 如果有正在进行的工序中检验 - if reuseForm: - wp.test.is_submited = False - wp.test.save() - else: - wp.test = None - wp.save() + last_test = wp.last_wp_test + if last_test and reuseForm: + last_test.is_midtesting = True + last_test.is_submited = False + last_test.save() + wp.test = last_test + wp.save() wp.operation = None wp.update_by = request.user @@ -742,7 +741,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd raise exceptions.APIException('请选择物料产出') for i in omos: if i.subproduction_progress.is_main: - newstep, _, _ = WpmService.get_next_step( + newstep, _, _ = WpmService.get_step_info( i.subproduction_plan, step) wpr = dict(material=i.material, step=newstep, act_state=WProduct.WPR_ACT_STATE_DOWAIT, remark='', @@ -763,7 +762,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd if oms_w.count!=1: raise exceptions.APIException('产出数量应为1') # 校验单片数量是否正确, 暂时未写 - newstep, needTest, reuseForm = WpmService.get_next_step( + newstep, needTest, reuseForm = WpmService.get_step_info( oms_w.subproduction_plan, step) wproduct = WProduct() wproduct.material = oms_w.material @@ -771,25 +770,24 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd wproduct.subproduction_plan = oms_w.subproduction_plan if step == newstep: wproduct.act_state = WProduct.WPR_ACT_STATE_TOTEST - if wproduct.test: # 如果有正在进行的工序中检验 - if reuseForm: - wproduct.test.is_midtesting = False - wproduct.test.is_submited = False - wproduct.test.save() - else: - wproduct.test = None - wproduct.save() + last_test = wproduct.last_wp_test + if last_test and reuseForm: + last_test.is_midtesting = False + last_test.is_submited = False + last_test.save() + wproduct.test = last_test + wproduct.save() else: wproduct.act_state = WProduct.WPR_ACT_STATE_DOWAIT if needTest: wproduct.act_state = WProduct.WPR_ACT_STATE_TOTEST - if wproduct.test:# 如果有正在进行的工序中检验 - if reuseForm: - wproduct.test.is_submited = False - wproduct.test.save() - else: - wproduct.test = None - wproduct.save() + last_test = wproduct.last_wp_test + if last_test and reuseForm: + last_test.is_midtesting = True + last_test.is_submited = False + last_test.save() + wproduct.test = last_test + wproduct.save() # 更新子计划进度 WpmService.update_subproduction_progress_main(