diff --git a/hb_server/apps/pm/models.py b/hb_server/apps/pm/models.py index b63e1c1..663d885 100644 --- a/hb_server/apps/pm/models.py +++ b/hb_server/apps/pm/models.py @@ -32,12 +32,17 @@ class SubProductionPlan(CommonAModel): """ 子生产计划 """ + SUBPLAN_STATE_PLANING = 0 + SUBPLAN_STATE_ASSGINED = 1 + SUBPLAN_STATE_ACCEPTED = 2 + SUBPLAN_STATE_WORKING = 3 + SUBPLAN_STATE_DONE = 4 state_choices=( - (0, '制定中'), - (1, '已下达'), - (2, '已接收'), - (3, '生产中'), - (4, '已完成') + (SUBPLAN_STATE_PLANING, '制定中'), + (SUBPLAN_STATE_ASSGINED, '已下达'), + (SUBPLAN_STATE_ACCEPTED, '已接收'), + (SUBPLAN_STATE_WORKING, '生产中'), + (SUBPLAN_STATE_DONE, '已完成') ) production_plan = models.ForeignKey(ProductionPlan, verbose_name='关联主生产计划', on_delete=models.CASCADE) subproduction = models.ForeignKey(SubProduction, verbose_name='关联生产分解', on_delete=models.CASCADE, related_name='subplan_subprod') @@ -53,7 +58,7 @@ class SubProductionPlan(CommonAModel): steps = models.JSONField('工艺步骤', default=list) - state = models.IntegerField('状态', default=0) + state = models.IntegerField('状态', default=SUBPLAN_STATE_PLANING) start_date_real = models.DateField('实际开工日期', null=True, blank=True) end_date_real = models.DateField('实际完工日期', null=True, blank=True) is_picked = models.BooleanField('是否已领料', default=False) diff --git a/hb_server/apps/pm/signals.py b/hb_server/apps/pm/signals.py index 49874bd..6114b88 100644 --- a/hb_server/apps/pm/signals.py +++ b/hb_server/apps/pm/signals.py @@ -1,6 +1,6 @@ from django.db.models.signals import post_save from django.dispatch import receiver -from apps.pm.models import SubProductionProgress +from apps.pm.models import SubProductionPlan, SubProductionProgress @receiver(post_save, sender=SubProductionProgress) def update_subplan_main(sender, instance, created, **kwargs): @@ -13,8 +13,8 @@ def update_subplan_main(sender, instance, created, **kwargs): subplan.main_product = instance.material subplan.main_count = instance.count subplan.main_count_real = instance.count_real - if instance.count_real>= instance.count: - subplan.state = 4 + if instance.count_real>= instance.count and instance.count_real != 0: + subplan.state = SubProductionPlan.SUBPLAN_STATE_DONE subplan.save() diff --git a/hb_server/apps/pm/views.py b/hb_server/apps/pm/views.py index c1999ea..a86d146 100644 --- a/hb_server/apps/pm/views.py +++ b/hb_server/apps/pm/views.py @@ -133,8 +133,8 @@ class SubProductionPlanViewSet(CreateUpdateModelAMixin, ListModelMixin, UpdateMo 下达任务 """ obj = self.get_object() - if obj.state == 0: - obj.state = 1 + if obj.state == SubProductionPlan.SUBPLAN_STATE_PLANING: + obj.state = SubProductionPlan.SUBPLAN_STATE_ASSGINED obj.save() return Response() raise APIException('计划状态有误') @@ -145,8 +145,8 @@ class SubProductionPlanViewSet(CreateUpdateModelAMixin, ListModelMixin, UpdateMo 开始生产 """ obj = self.get_object() - if obj.state in [1,2]: - obj.state = 3 + if obj.state in [SubProductionPlan.SUBPLAN_STATE_ASSGINED, SubProductionPlan.SUBPLAN_STATE_ACCEPTED]: + obj.state = SubProductionPlan.SUBPLAN_STATE_WORKING obj.start_date_real = timezone.now() obj.save() return Response() diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index 31dbea7..fc6be42 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -32,7 +32,8 @@ class PickSerializer(serializers.Serializer): def create(self, validated_data): picks = validated_data.pop('picks') sp = validated_data.pop('subproduction_plan') - if sp.state not in [1, 2, 3]: + if sp.state not in [SubProductionPlan.SUBPLAN_STATE_ASSGINED, SubProductionPlan.SUBPLAN_STATE_ACCEPTED, + SubProductionPlan.SUBPLAN_STATE_WORKING]: raise exceptions.ValidationError('该子计划状态错误') # if sp.is_picked: # raise exceptions.ValidationError('该子计划已领料') @@ -48,6 +49,7 @@ class PickSerializer(serializers.Serializer): with transaction.atomic(): fifo = FIFO.objects.create(type=FIFO.FIFO_TYPE_DO_OUT, inout_date=timezone.now(), create_by=self.context['request'].user) for i in picks: + isLowLevel = False # 更新出库详情 i['count'] = i.pop('pick_count', 0) # 是否勾选每一个 @@ -55,7 +57,8 @@ class PickSerializer(serializers.Serializer): i['count'] = len(i['iproducts']) isLowLevel = True if i['count']>0: - i.pop('iproducts') + if isLowLevel: + iproducts = i.pop('iproducts') i['fifo'] = fifo i['is_testok'] = True # 默认检测合格 i['subproduction_plan'] = sp @@ -63,7 +66,7 @@ class PickSerializer(serializers.Serializer): # 创建再下一个层级 if isLowLevel: mls = [] - for m in i['iproducts']: + for m in iproducts: ml = {} ml['material'] = m.material ml['number'] = m.number @@ -88,14 +91,16 @@ class PickSerializer(serializers.Serializer): spp.save() if spp.count_pick > spp.count: raise exceptions.APIException('超过计划需求数') - # 更新半成品表 - wproducts = WProduct.objects.filter(pk__in=[x.wproduct for x in i['iproducts']]) - first_step = Step.objects.get(pk=sp.steps[0].id) - wproducts.update(step=first_step, is_executed=False, - act_state=WProduct.WPR_ACT_STATE_DOING, is_hidden=False, warehouse=None, - subproduction_plan=sp, production_plan=sp.production_plan) + if isLowLevel: + # 更新半成品表 + wids = IProduct.objects.filter(pk__in=[x.id for x in iproducts]).values_list('wproduct', flat=True) + wproducts = WProduct.objects.filter(pk__in=wids) + first_step = Step.objects.get(pk=sp.steps[0]['id']) + wproducts.update(step=first_step, is_executed=False, + act_state=WProduct.WPR_ACT_STATE_DOING, is_hidden=False, warehouse=None, + subproduction_plan=sp, production_plan=sp.production_plan) sp.is_picked=True - sp.state = 3 #生产中 + sp.state = SubProductionPlan.SUBPLAN_STATE_WORKING #生产中 sp.state_date_real = timezone.now() #实际开工日期 sp.save() # 更新库存 diff --git a/hb_server/apps/wpm/views.py b/hb_server/apps/wpm/views.py index 1ff9c5d..1b63890 100644 --- a/hb_server/apps/wpm/views.py +++ b/hb_server/apps/wpm/views.py @@ -442,7 +442,7 @@ class DoFormSubmit(CreateAPIView, GenericAPIView): else: for wproduct in vdata['wproducts']: # 获取下一步子工序 - newstep, hasNext = WpmServies.get_next_step(i['subproduction_plan'], vdata['step']) + newstep, hasNext = WpmServies.get_next_step(wproduct.subproduction_plan, vdata['step']) wproduct.step = newstep wproduct.pre_step=vdata['step'] if hasNext: