子工序检查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()
|
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):
|
class WprouctTicket(CommonAModel):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -3,7 +3,7 @@ from typing import List
|
||||||
|
|
||||||
from django.db.models.expressions import F
|
from django.db.models.expressions import F
|
||||||
from apps.pm.models import ProductionPlan, SubProductionPlan, SubProductionProgress
|
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.qm.models import TestRecord
|
||||||
from apps.system.models import User
|
from apps.system.models import User
|
||||||
from apps.wf.models import State, TicketFlow, Transition
|
from apps.wf.models import State, TicketFlow, Transition
|
||||||
|
@ -13,19 +13,38 @@ from rest_framework.exceptions import ParseError
|
||||||
class WpmService(object):
|
class WpmService(object):
|
||||||
|
|
||||||
@classmethod
|
@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
|
used_steps = UsedStep.objects.filter(subproduction=subproduction_plan.subproduction).order_by('step__number')
|
||||||
stepIds = [i['id'] for i in steps_list]
|
for index, i in enumerate(used_steps):
|
||||||
pindex = stepIds.index(nowstep.id)
|
if i.step == nowstep and get_next:
|
||||||
need_test = steps_list[pindex].get('need_test', False)
|
try:
|
||||||
reuse_form = steps_list[pindex].get('reuse_form', True)
|
used_step = used_steps[index+1]
|
||||||
if pindex + 1 < len(stepIds):
|
return used_step, used_step.need_test, used_step.reuse_form
|
||||||
return Step.objects.get(pk=stepIds[pindex+1]), need_test, reuse_form
|
except:
|
||||||
else:
|
return nowstep, i.need_test, i.reuse_form
|
||||||
return nowstep, need_test, 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
|
@classmethod
|
||||||
def get_subplans_queryset_from_wproducts(cls, wproducts:List):
|
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:
|
elif wproduct.act_state == WProduct.WPR_ACT_STATE_TOCOMBTEST:
|
||||||
savedict['type'] = TestRecord.TEST_COMB
|
savedict['type'] = TestRecord.TEST_COMB
|
||||||
elif wproduct.act_state == WProduct.WPR_ACT_STATE_TOTEST:
|
elif wproduct.act_state == WProduct.WPR_ACT_STATE_TOTEST:
|
||||||
_, need_test, _ = WpmService.get_next_step(wproduct.subproduction_plan, wproduct.step)
|
step, need_test, _ = WpmService.get_step_info(wproduct.subproduction_plan, wproduct.step, get_next=False)
|
||||||
if need_test:
|
if need_test and wproduct.step != step:
|
||||||
savedict['is_midtesting'] = True
|
savedict['is_midtesting'] = True
|
||||||
# if UsedStep.objects.filter(subproduction=wproduct.subproduction_plan.subproduction).first().need_test:
|
# if UsedStep.objects.filter(subproduction=wproduct.subproduction_plan.subproduction).first().need_test:
|
||||||
tr = TestRecord.objects.create(**savedict)
|
tr = TestRecord.objects.create(**savedict)
|
||||||
|
@ -700,32 +700,31 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd
|
||||||
wsp = i.subproduction_plan
|
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.step = newstep
|
||||||
wp.pre_step = step
|
wp.pre_step = step
|
||||||
wp.material = wsp.product
|
wp.material = wsp.product
|
||||||
|
|
||||||
if step == newstep:
|
if step == newstep:
|
||||||
wp.act_state = WProduct.WPR_ACT_STATE_TOTEST
|
wp.act_state = WProduct.WPR_ACT_STATE_TOTEST
|
||||||
if wp.test:# 如果有正在进行的工序中检验
|
last_test = wp.last_wp_test
|
||||||
if reuseForm:
|
if last_test and reuseForm:
|
||||||
wp.test.is_midtesting = False
|
last_test.is_midtesting = False
|
||||||
wp.test.is_submited = False
|
last_test.is_submited = False
|
||||||
wp.test.save()
|
last_test.save()
|
||||||
else:
|
wp.test = last_test
|
||||||
wp.test = None
|
wp.save()
|
||||||
wp.save()
|
|
||||||
else:
|
else:
|
||||||
wp.act_state = WProduct.WPR_ACT_STATE_DOWAIT
|
wp.act_state = WProduct.WPR_ACT_STATE_DOWAIT
|
||||||
if needTest: #子工序若需要检验
|
if needTest: #子工序若需要检验
|
||||||
wp.act_state = WProduct.WPR_ACT_STATE_TOTEST
|
wp.act_state = WProduct.WPR_ACT_STATE_TOTEST
|
||||||
if wp.test:# 如果有正在进行的工序中检验
|
last_test = wp.last_wp_test
|
||||||
if reuseForm:
|
if last_test and reuseForm:
|
||||||
wp.test.is_submited = False
|
last_test.is_midtesting = True
|
||||||
wp.test.save()
|
last_test.is_submited = False
|
||||||
else:
|
last_test.save()
|
||||||
wp.test = None
|
wp.test = last_test
|
||||||
wp.save()
|
wp.save()
|
||||||
|
|
||||||
wp.operation = None
|
wp.operation = None
|
||||||
wp.update_by = request.user
|
wp.update_by = request.user
|
||||||
|
@ -742,7 +741,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd
|
||||||
raise exceptions.APIException('请选择物料产出')
|
raise exceptions.APIException('请选择物料产出')
|
||||||
for i in omos:
|
for i in omos:
|
||||||
if i.subproduction_progress.is_main:
|
if i.subproduction_progress.is_main:
|
||||||
newstep, _, _ = WpmService.get_next_step(
|
newstep, _, _ = WpmService.get_step_info(
|
||||||
i.subproduction_plan, step)
|
i.subproduction_plan, step)
|
||||||
wpr = dict(material=i.material, step=newstep,
|
wpr = dict(material=i.material, step=newstep,
|
||||||
act_state=WProduct.WPR_ACT_STATE_DOWAIT, remark='',
|
act_state=WProduct.WPR_ACT_STATE_DOWAIT, remark='',
|
||||||
|
@ -763,7 +762,7 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd
|
||||||
if oms_w.count!=1:
|
if oms_w.count!=1:
|
||||||
raise exceptions.APIException('产出数量应为1')
|
raise exceptions.APIException('产出数量应为1')
|
||||||
# 校验单片数量是否正确, 暂时未写
|
# 校验单片数量是否正确, 暂时未写
|
||||||
newstep, needTest, reuseForm = WpmService.get_next_step(
|
newstep, needTest, reuseForm = WpmService.get_step_info(
|
||||||
oms_w.subproduction_plan, step)
|
oms_w.subproduction_plan, step)
|
||||||
wproduct = WProduct()
|
wproduct = WProduct()
|
||||||
wproduct.material = oms_w.material
|
wproduct.material = oms_w.material
|
||||||
|
@ -771,25 +770,24 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd
|
||||||
wproduct.subproduction_plan = oms_w.subproduction_plan
|
wproduct.subproduction_plan = oms_w.subproduction_plan
|
||||||
if step == newstep:
|
if step == newstep:
|
||||||
wproduct.act_state = WProduct.WPR_ACT_STATE_TOTEST
|
wproduct.act_state = WProduct.WPR_ACT_STATE_TOTEST
|
||||||
if wproduct.test: # 如果有正在进行的工序中检验
|
last_test = wproduct.last_wp_test
|
||||||
if reuseForm:
|
if last_test and reuseForm:
|
||||||
wproduct.test.is_midtesting = False
|
last_test.is_midtesting = False
|
||||||
wproduct.test.is_submited = False
|
last_test.is_submited = False
|
||||||
wproduct.test.save()
|
last_test.save()
|
||||||
else:
|
wproduct.test = last_test
|
||||||
wproduct.test = None
|
wproduct.save()
|
||||||
wproduct.save()
|
|
||||||
else:
|
else:
|
||||||
wproduct.act_state = WProduct.WPR_ACT_STATE_DOWAIT
|
wproduct.act_state = WProduct.WPR_ACT_STATE_DOWAIT
|
||||||
if needTest:
|
if needTest:
|
||||||
wproduct.act_state = WProduct.WPR_ACT_STATE_TOTEST
|
wproduct.act_state = WProduct.WPR_ACT_STATE_TOTEST
|
||||||
if wproduct.test:# 如果有正在进行的工序中检验
|
last_test = wproduct.last_wp_test
|
||||||
if reuseForm:
|
if last_test and reuseForm:
|
||||||
wproduct.test.is_submited = False
|
last_test.is_midtesting = True
|
||||||
wproduct.test.save()
|
last_test.is_submited = False
|
||||||
else:
|
last_test.save()
|
||||||
wproduct.test = None
|
wproduct.test = last_test
|
||||||
wproduct.save()
|
wproduct.save()
|
||||||
|
|
||||||
# 更新子计划进度
|
# 更新子计划进度
|
||||||
WpmService.update_subproduction_progress_main(
|
WpmService.update_subproduction_progress_main(
|
||||||
|
|
Loading…
Reference in New Issue