diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index 5197848..b35fa0b 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -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) diff --git a/hb_server/apps/wpm/services.py b/hb_server/apps/wpm/services.py new file mode 100644 index 0000000..de6e5c8 --- /dev/null +++ b/hb_server/apps/wpm/services.py @@ -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 \ No newline at end of file diff --git a/hb_server/apps/wpm/views.py b/hb_server/apps/wpm/views.py index b387741..91c7524 100644 --- a/hb_server/apps/wpm/views.py +++ b/hb_server/apps/wpm/views.py @@ -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']: