子工序检查bug
This commit is contained in:
parent
0b0fab4b0a
commit
f2af3e4a8d
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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,31 +700,30 @@ 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
|
||||
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: #子工序若需要检验
|
||||
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
|
||||
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
|
||||
|
@ -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,24 +770,23 @@ 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
|
||||
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
|
||||
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()
|
||||
|
||||
# 更新子计划进度
|
||||
|
|
Loading…
Reference in New Issue