From da1237c421d055d01da19d1a9a728c1736ce2d4d Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 18 Nov 2021 08:52:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AD=90=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E8=BF=9B=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/pm/models.py | 17 +++++++++++------ hb_server/apps/pm/signals.py | 6 +++--- hb_server/apps/pm/views.py | 8 ++++---- hb_server/apps/wpm/serializers.py | 5 +++-- 4 files changed, 21 insertions(+), 15 deletions(-) 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..38597bd 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('该子计划已领料') @@ -95,7 +96,7 @@ class PickSerializer(serializers.Serializer): 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() # 更新库存