子工序操作

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