From da1237c421d055d01da19d1a9a728c1736ce2d4d Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 18 Nov 2021 08:52:15 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AD=90=E8=AE=A1?= =?UTF-8?q?=E5=88=92=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() # 更新库存 From 4db45b69325dfb5a896392b371fcf24306afacd3 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 18 Nov 2021 08:56:41 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E9=A2=86=E6=96=99bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/wpm/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index 38597bd..488ceaa 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -56,7 +56,7 @@ class PickSerializer(serializers.Serializer): i['count'] = len(i['iproducts']) isLowLevel = True if i['count']>0: - i.pop('iproducts') + i.pop('iproducts', None) i['fifo'] = fifo i['is_testok'] = True # 默认检测合格 i['subproduction_plan'] = sp From 161e6f78ade2eef0344a0c26036aa6468f4b1c92 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 18 Nov 2021 08:58:26 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E9=A2=86=E6=96=99bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/wpm/serializers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index 488ceaa..980acfd 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -56,7 +56,8 @@ class PickSerializer(serializers.Serializer): i['count'] = len(i['iproducts']) isLowLevel = True if i['count']>0: - i.pop('iproducts', None) + if 'iproducts' in i: + iproducts = i.pop('iproducts') i['fifo'] = fifo i['is_testok'] = True # 默认检测合格 i['subproduction_plan'] = sp @@ -64,7 +65,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 From 9bf2e94b53a05204937e5d202474b32dcca02d0c Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 18 Nov 2021 09:01:30 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E9=A2=86=E6=96=99bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/wpm/serializers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index 980acfd..a8fa14a 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -49,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) # 是否勾选每一个 From c0d8772a47807d8f4dfbe80e1adf72ab4f00ac6b Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 18 Nov 2021 09:05:16 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E9=A2=86=E6=96=99bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/wpm/serializers.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index a8fa14a..96ee033 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -57,7 +57,7 @@ class PickSerializer(serializers.Serializer): i['count'] = len(i['iproducts']) isLowLevel = True if i['count']>0: - if 'iproducts' in i: + if isLowLevel: iproducts = i.pop('iproducts') i['fifo'] = fifo i['is_testok'] = True # 默认检测合格 @@ -91,12 +91,13 @@ 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: + # 更新半成品表 + 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) sp.is_picked=True sp.state = SubProductionPlan.SUBPLAN_STATE_WORKING #生产中 sp.state_date_real = timezone.now() #实际开工日期 From d129bf878a30e0e82a726983589696bebc1de0b6 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 18 Nov 2021 09:09:34 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E5=8D=8A=E6=88=90=E5=93=81=E9=A2=86?= =?UTF-8?q?=E6=96=99bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/wpm/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index 96ee033..a0c479e 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -93,7 +93,7 @@ class PickSerializer(serializers.Serializer): raise exceptions.APIException('超过计划需求数') if isLowLevel: # 更新半成品表 - wproducts = WProduct.objects.filter(pk__in=[x.wproduct for x in i['iproducts']]) + wproducts = WProduct.objects.filter(pk__in=[x.wproduct for x in 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, From c967d63db47b8f0c1d49ca84137ebd07f7292ff0 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 18 Nov 2021 09:14:26 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E5=8D=8A=E6=88=90=E5=93=81=E9=A2=86?= =?UTF-8?q?=E6=96=99bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/wpm/serializers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index a0c479e..040de52 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -93,7 +93,8 @@ class PickSerializer(serializers.Serializer): raise exceptions.APIException('超过计划需求数') if isLowLevel: # 更新半成品表 - wproducts = WProduct.objects.filter(pk__in=[x.wproduct for x in iproducts]) + wids = IProduct.objects.filter(pk__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, From d83aa0d3e89db3900c288a2f7c57cbe5e2449d23 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 18 Nov 2021 09:17:54 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E5=8D=8A=E6=88=90=E5=93=81=E9=A2=86?= =?UTF-8?q?=E6=96=99bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/wpm/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index 040de52..778e48e 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -93,7 +93,7 @@ class PickSerializer(serializers.Serializer): raise exceptions.APIException('超过计划需求数') if isLowLevel: # 更新半成品表 - wids = IProduct.objects.filter(pk__in=iproducts).values_list('wproduct', flat=True) + wids = 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, From 6482a841d5c7a85a039604474288f31a6ef02032 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 18 Nov 2021 09:19:27 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E5=8D=8A=E6=88=90=E5=93=81=E9=A2=86?= =?UTF-8?q?=E6=96=99bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/wpm/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index 778e48e..9294ec4 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -93,7 +93,7 @@ class PickSerializer(serializers.Serializer): raise exceptions.APIException('超过计划需求数') if isLowLevel: # 更新半成品表 - wids = iproducts.values_list('wproduct', flat=True) + 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, From decb1e4aac794bca2eebe7aa73b9f8a428d28f3d Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 18 Nov 2021 09:21:21 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E5=8D=8A=E6=88=90=E5=93=81=E9=A2=86?= =?UTF-8?q?=E6=96=99bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/wpm/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hb_server/apps/wpm/serializers.py b/hb_server/apps/wpm/serializers.py index 9294ec4..fc6be42 100644 --- a/hb_server/apps/wpm/serializers.py +++ b/hb_server/apps/wpm/serializers.py @@ -95,7 +95,7 @@ class PickSerializer(serializers.Serializer): # 更新半成品表 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) + 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) From 216537c74261b71ed0d72eeb007ae0723decf074 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 18 Nov 2021 09:42:06 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8B=E4=B8=80?= =?UTF-8?q?=E6=AD=A5=E5=AD=90=E5=B7=A5=E5=BA=8Fbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hb_server/apps/wpm/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: