子工序操作

This commit is contained in:
caoqianming 2021-11-15 11:23:01 +08:00
parent a78a10c3fa
commit b09b3996ac
3 changed files with 62 additions and 46 deletions

View File

@ -113,7 +113,7 @@ class OperationListSerializer(serializers.ModelSerializer):
class OperationInitSerializer(serializers.Serializer):
step = serializers.PrimaryKeyRelatedField(queryset=Step.objects.all(), label="子工序ID")
# subproduction_plan = serializers.PrimaryKeyRelatedField(queryset=SubProductionPlan.objects.all(), label="子计划ID", required=False)
subproduction_plan = serializers.PrimaryKeyRelatedField(queryset=SubProductionPlan.objects.all(), label="子计划ID", required=False)
wproducts = serializers.ListField(child=
serializers.PrimaryKeyRelatedField(queryset=WProduct.objects.all()), label="半成品ID列表", required=False)
@ -165,7 +165,7 @@ class OperationRecordSerializer(serializers.ModelSerializer):
class OperationSubmitSerializer(serializers.Serializer):
step = serializers.PrimaryKeyRelatedField(queryset=Step.objects.all(), label="子工序ID")
# subproduction_plan = serializers.PrimaryKeyRelatedField(queryset=SubProductionPlan.objects.all(), label="子计划ID", required=False)
subproduction_plan = serializers.PrimaryKeyRelatedField(queryset=SubProductionPlan.objects.all(), label="子计划ID", required=False)
wproducts = serializers.ListField(child=
serializers.PrimaryKeyRelatedField(queryset=WProduct.objects.all()), label="半成品ID列表", required=False)
input = DoInputSerializer(many=True, required=False)

View File

@ -0,0 +1,15 @@
from apps.pm.models import SubProductionPlan
from apps.mtm.models import Step
class WpmServies(object):
@classmethod
def get_next_step(cls, subproduction_plan:SubProductionPlan, nowstep:Step):
"""
获取下一步骤
"""
stepIds = [i['id'] for i in subproduction_plan.steps]
pindex = stepIds.index(nowstep.id)
if pindex + 1 < len(stepIds):
return Step.objects.get(pk=stepIds[pindex+1]), True
else:
return nowstep, False

View File

@ -19,6 +19,8 @@ from apps.wpm.serializers import OperationDetailSerializer, OperationListSeriali
from rest_framework.response import Response
from django.db import transaction
from rest_framework import exceptions
from apps.wpm.services import WpmServies
# Create your views here.
class WPlanViewSet(ListModelMixin, GenericViewSet):
"""
@ -158,9 +160,15 @@ class DoFormInit(CreateAPIView, GenericAPIView):
ret_0['wproducts'] = data['wproducts']
splans = WProduct.objects.filter(id__in=data['wproducts']).values('subproduction_plan', flat=True)
# 调出所属子计划现有物料
ret_0['input'] = WMaterialListSerializer(instance=WMaterial.objects.filter(subproduction_plan__in=splans), many=True)
ret_0['input'] = WMaterialListSerializer(instance=WMaterial.objects.filter(subproduction_plan__in=splans), many=True).data
else:
if 'subproduction_plan' in vdata:
splans = [vdata['subproduction_plan']]
else:
splans = SubProductionPlan.objects.filter(is_deleted=False,
subproduction__usedstep_subproduction__step=vdata['step'], state=3)
ret_0['wproducts'] = []
ret_0['input'] = WMaterialListSerializer(instance=WMaterial.objects.filter(subproduction_plan__in=splans), many=True).data
for i in ret_0['input']:
@ -172,9 +180,7 @@ class DoFormInit(CreateAPIView, GenericAPIView):
subproduction_plan__in=splans, type=SubprodctionMaterial.SUB_MA_TYPE_OUT).exclude(is_main=True)
else:
# 此时显示所有子计划的情况
splans = SubProductionPlan.objects.filter(is_deleted=False,
subproduction__usedstep_subproduction__step=vdata['step'], state=3)
# 此时显示所有子计划需要输出的物料
o_objs = SubProductionProgress.objects.filter(
subproduction_plan__in=splans, type=SubprodctionMaterial.SUB_MA_TYPE_OUT)
ret_0['output'] = list(o_objs.values('subproduction_plan', 'material', 'material__name', 'material__number'))
@ -238,9 +244,8 @@ class DoFormSubmit(CreateAPIView, GenericAPIView):
# 如果是切割
# 获取下一步子工序
if vdata['step'].type == Step.STEP_TYPE_DIV:
stepIds = [i['id'] for i in i['subproduction_plan'].steps]
pindex = stepIds.index(vdata['step'].id)
wpr = dict(m_state=ma, p_state=Step.objects.get(pk=stepIds[pindex+1]),
newstep, _ = WpmServies.get_next_step(i['subproduction_plan'], vdata['step'])
wpr = dict(m_state=ma, p_state=newstep,
act_state=WProduct.WPR_ACT_STATE_DOING, is_executed=False, remark='',
subproduction_plan=i['subproduction_plan'],
production_plan=i['subproduction_plan'].production_plan)
@ -262,44 +267,40 @@ class DoFormSubmit(CreateAPIView, GenericAPIView):
sp.save()
# 更新动态产品表
if 'wproducts' in vdata and data['wproducts']:
for i in data['wproducts']:
pass
wproducts = WProduct.objects.filter(pk__in=data['wproducts'])
# 获取下一步子工序
stepIds = [i['id'] for i in vdata['subproduction_plan'].steps]
pindex = stepIds.index(vdata['step'].id)
if pindex + 1 < len(stepIds): # 如果不是最后一步
newstep = Step.objects.get(pk=stepIds[pindex+1])
wproducts.update(p_state=newstep, is_executed=False, pre_pstate=vdata['step'])
# 特殊情况如果是夹层结合
if vdata['step'].type == Step.STEP_TYPE_COMB:
if 'wproducts' in vdata and vdata['wproducts']:
if vdata['step'].type == Step.STEP_TYPE_COMB:
wproducts = vdata['wproducts']
if 'suproduction_plan' in vdata:
wproducts.update(is_hidden=True) # 隐藏
WProduct.objects.create(
m_state=vdata['subproduction_plan'].main_product, p_state = newstep,
act_state=WProduct.WPR_ACT_STATE_DOING, is_executed=False, remark='',
subproduction_plan=vdata['subproduction_plan'],
production_plan=vdata['subproduction_plan'].production_plan,
parent = data['wproducts']
)
else: # 如果是最后一步, 此时需要转序并更新状态为待检测, 此时物料状态需变成当前子计划的主产物状态
newstep = vdata['step']
wproducts.update(p_state=newstep, is_executed=True,
act_state=WProduct.WPR_ACT_STATE_TOTEST, pre_pstate=newstep, m_state=vdata['subproduction_plan'].main_product)
# 特殊情况如果是夹层结合
if vdata['step'].type == Step.STEP_TYPE_COMB:
wproducts.update(is_hidden=True) # 隐藏
WProduct.objects.create(
m_state=vdata['subproduction_plan'].main_product, p_state = newstep,
act_state=WProduct.WPR_ACT_STATE_TOTEST, is_executed=True, remark='',
subproduction_plan=vdata['subproduction_plan'],
production_plan=vdata['subproduction_plan'].production_plan
)
newstep, hasNext = WpmServies.get_next_step(i['subproduction_plan'], vdata['step'])
wproduct = WProduct()
wproduct.m_state = vdata['subproduction_plan'].main_product
wproduct.p_state = newstep
wproduct.subproduction_plan=vdata['subproduction_plan']
wproduct.production_plan=vdata['subproduction_plan'].production_plan
wproduct.parent = data['wproducts']
if hasNext:
wproduct.act_state=WProduct.WPR_ACT_STATE_DOING
wproduct.is_executed=False
else:
wproduct.act_state=WProduct.WPR_ACT_STATE_TOTEST
wproduct.is_executed=True
wproduct.save()
else:
raise exceptions.APIException('请指定子计划')
else:
for wproduct in vdata['wproducts']:
# 获取下一步子工序
newstep, hasNext = WpmServies.get_next_step(i['subproduction_plan'], vdata['step'])
wproduct.p_state = newstep
wproduct.pre_pstate=vdata['step']
if hasNext:
wproduct.is_executed= False
else:
wproduct.is_executed= True
wproduct.act_state=WProduct.WPR_ACT_STATE_TOTEST
wproduct.m_state=wproduct.subproduction_plan.main_product
wproduct.save()
# 保存自定义表单结果
for i in vdata['forms']: