From a0e56d3666f5dafc5a50f4cf1c88c9836de0fe08 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Tue, 23 Nov 2021 09:46:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wpm/migrations/0021_auto_20211123_0945.py | 21 +++++ hb_server/apps/wpm/models.py | 2 - hb_server/apps/wpm/views.py | 86 ++++++++++++++++--- hb_server/utils/view.py | 2 +- 4 files changed, 95 insertions(+), 16 deletions(-) create mode 100644 hb_server/apps/wpm/migrations/0021_auto_20211123_0945.py diff --git a/hb_server/apps/wpm/migrations/0021_auto_20211123_0945.py b/hb_server/apps/wpm/migrations/0021_auto_20211123_0945.py new file mode 100644 index 0000000..c8b651a --- /dev/null +++ b/hb_server/apps/wpm/migrations/0021_auto_20211123_0945.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.9 on 2021-11-23 01:45 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('wpm', '0020_alter_operationwproduct_wproduct'), + ] + + operations = [ + migrations.RemoveField( + model_name='operationwproduct', + name='production_plan', + ), + migrations.RemoveField( + model_name='wproduct', + name='production_plan', + ), + ] diff --git a/hb_server/apps/wpm/models.py b/hb_server/apps/wpm/models.py index f2d3f5f..ee835a1 100644 --- a/hb_server/apps/wpm/models.py +++ b/hb_server/apps/wpm/models.py @@ -43,7 +43,6 @@ class WProduct(CommonAModel): parent = models.JSONField('父', default=list, blank=True) remark = models.CharField('备注', max_length=200, null=True, blank=True) subproduction_plan = models.ForeignKey(SubProductionPlan, verbose_name='当前子生产计划', on_delete=models.CASCADE, related_name='wproduct_subplan') - production_plan = models.ForeignKey(ProductionPlan, verbose_name='关联主生产计划', on_delete=models.CASCADE) warehouse = models.ForeignKey(WareHouse, verbose_name='所在仓库', on_delete=models.SET_NULL, null=True, blank=True) operation = models.ForeignKey('wpm.operation', verbose_name='关联操作', on_delete=models.SET_NULL, null=True, blank=True, related_name='current_operation') @@ -66,7 +65,6 @@ class OperationWproduct(BaseModel): number = models.CharField('物品编号', null=True, blank=True, max_length=50) material = models.ForeignKey(Material, verbose_name='操作时的物料状态', on_delete=models.CASCADE) subproduction_plan = models.ForeignKey(SubProductionPlan, verbose_name='当前子生产计划', on_delete=models.CASCADE) - production_plan = models.ForeignKey(ProductionPlan, verbose_name='当前主生产计划', on_delete=models.CASCADE) class OperationMaterial(BaseModel): diff --git a/hb_server/apps/wpm/views.py b/hb_server/apps/wpm/views.py index 3c8e00d..c0fc856 100644 --- a/hb_server/apps/wpm/views.py +++ b/hb_server/apps/wpm/views.py @@ -69,7 +69,7 @@ class WPlanViewSet(ListModelMixin, GenericViewSet): wps = WProduct.objects.filter(pk__in=[x for x in i['wproducts']]) wps.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, update_by=request.user, update_time=timezone.now()) + subproduction_plan=sp, update_by=request.user, update_time=timezone.now()) return Response() @@ -84,7 +84,7 @@ class WPlanViewSet(ListModelMixin, GenericViewSet): vdata = serializer.data subplan = self.get_object() material = subplan.main_product - batch = subplan.production_plan.number + batch = subplan.number warehouse = WareHouse.objects.get(id=vdata['warehouse']) wproducts = WProduct.objects.filter(subproduction_plan=subplan, act_state=WProduct.WPR_ACT_STATE_OK, material=material, is_deleted=False) @@ -160,7 +160,7 @@ class WProductViewSet(ListModelMixin, GenericViewSet): perms_map={'*':'*'} queryset = WProduct.objects.select_related('step', 'material').filter(is_hidden=False).exclude(operation=None) serializer_class = WProductListSerializer - filterset_fields = ['step', 'subproduction_plan', 'material', 'production_plan', 'step__process', 'act_state'] + filterset_fields = ['step', 'subproduction_plan', 'material', 'step__process', 'act_state'] search_fields = ['number'] ordering_fields = ['id'] ordering = ['id'] @@ -207,7 +207,7 @@ class WProductViewSet(ListModelMixin, GenericViewSet): # 更新子计划主产品数 instance = SubProductionProgress.objects.get(subproduction_plan=wproduct.subproduction_plan, is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT) - instance.count_real = instance.count_real + 1 # 这个地方可能会有问题 + instance.count_ok = instance.count_ok + 1 # 这个地方可能会有问题 instance.save() else:# 如果不合格 pass @@ -228,7 +228,7 @@ class WProductViewSet(ListModelMixin, GenericViewSet): if wproduct.act_state != WProduct.WPR_ACT_STATE_OK: raise exceptions.APIException('半成品不可入库') material = wproduct.material - batch = wproduct.production_plan.number + batch = wproduct.subproduction_plan.number # 创建入库记录 remark = vdata.get('remark', '') fifo = FIFO.objects.create(type=FIFO.FIFO_TYPE_DO_IN, @@ -314,7 +314,6 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd owp['number'] = wpd.number owp['material'] = wpd.material owp['subproduction_plan'] = wpd.subproduction_plan - owp['production_plan'] = wpd.production_plan owps.append(OperationWproduct(**owp)) OperationWproduct.objects.bulk_create(owps) else: @@ -350,6 +349,10 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd 提交车间操作重要 """ op = self.get_object() + step = op.step + # 检查自定义表单填写 + if OperationRecord.objects.filter(operation=op, is_filled=False).exists(): + raise exceptions.APIException('存在自定义表单未填写') # 更新物料消耗进度 for i in OperationMaterial.objects.filter(operation=op, type=SubprodctionMaterial.SUB_MA_TYPE_IN): # 更新车间物料 @@ -360,9 +363,69 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd sp = i_wmat.subproduction_plan sp.count_real = sp.count_real + i['count'] sp.save() - # 更新物料产出情况 - - + # 更新产出 + for i in OperationMaterial.objects.filter(operation=op, type=SubprodctionMaterial.SUB_MA_TYPE_OUT): + if not i.subproduction_progress.is_main: + # 更新车间物料产出情况 + ins, _ = WMaterial.objects.get_or_create(subproduction_plan=i.subproduction_plan, + material=i.material) + ins.count = ins.count + i['count'] + ins.save() + # 更新子计划物料产出情况 + sp = i.subproduction_progress + sp.count_real = sp.count_real + i['count'] + sp.save() + # 更新动态产品表 + if step.type == Step.STEP_TYPE_NOM: + for i in OperationWproduct.objects.filter(operation=op): + wp = i.wproduct + wsp = i.subproduction_plan + # 获取下一步子工序 + newstep, hasNext = WpmServies.get_next_step(wsp, step) + wp.step = newstep + wp.pre_step = step + if hasNext: + wp.is_executed= False + else: + wp.is_executed = True + wp.act_state = WProduct.WPR_ACT_STATE_TOTEST + wp.material = wsp.main_product + # 更新子计划进度 + instance = SubProductionProgress.objects.get(subproduction_plan=wsp, + is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT) + instance.count_real = instance.count_real + 1 # 这个地方可能会有问题,不够严谨 + instance.save() + wp.operation = None + wp.save() + elif step.type == Step.STEP_TYPE_DIV: + # 更新物料产出情况 + for i in OperationMaterial.objects.filter(operation=op, type=SubprodctionMaterial.SUB_MA_TYPE_OUT): + if i.subproduction_progress.is_main: + newstep, _ = WpmServies.get_next_step(i.subproduction_plan, step) + wpr = dict(material=i.material, step=newstep, + act_state=WProduct.WPR_ACT_STATE_DOING, is_executed=False, remark='', + subproduction_plan=i.subproduction_plan) + for x in range(i.count): + WProduct.objects.create(**wpr) + elif step.type == Step.STEP_TYPE_COMB: + # 隐藏原半成品 + ows = OperationWproduct.objects.filter(operation=op) + ows.update(is_hidden=True) + if i.subproduction_progress.is_main: + newstep, hasNext = WpmServies.get_next_step(i.subproduction_plan, step) + wproduct = WProduct() + wproduct.material = i.material + wproduct.step = newstep + wproduct.subproduction_plan = i.subproduction_plan + wproduct.parent = ows.values_list('wproduct', flat=True) + 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() + class OperationWproductViewSet(ListModelMixin, DestroyModelMixin, GenericViewSet): @@ -598,7 +661,6 @@ class DoFormSubmit(CreateAPIView, GenericAPIView): owp['number'] = wp.number owp['material'] = wp.material owp['subproduction_plan'] = wp.subproduction_plan - owp['production_plan'] = wp.production_plan owps.append(OperationWproduct(**owp)) OperationWproduct.objects.bulk_create(owps) @@ -628,8 +690,7 @@ class DoFormSubmit(CreateAPIView, GenericAPIView): newstep, _ = WpmServies.get_next_step(i['subproduction_plan'], vdata['step']) wpr = dict(material=ma, step=newstep, act_state=WProduct.WPR_ACT_STATE_DOING, is_executed=False, remark='', - subproduction_plan=i['subproduction_plan'], - production_plan=i['subproduction_plan'].production_plan) + subproduction_plan=i['subproduction_plan']) for x in range(i['count_output']): WProduct.objects.create(**wpr) else: @@ -658,7 +719,6 @@ class DoFormSubmit(CreateAPIView, GenericAPIView): wproduct.material = vdata['subproduction_plan'].main_product wproduct.step = 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 diff --git a/hb_server/utils/view.py b/hb_server/utils/view.py index 07d1c30..8b07565 100644 --- a/hb_server/utils/view.py +++ b/hb_server/utils/view.py @@ -62,7 +62,7 @@ class UpdateDevelop(APIView): import os # 更新后端 os.chdir('/home/hberp') - ret = os.popen('git pull https://caoqianming%40ctc.ac.cn:9093qqww@e.coding.net/ctcdevteam/hberp/hberp.git origin develop') + ret = os.popen('git pull https://caoqianming%40ctc.ac.cn:9093qqww@e.coding.net/ctcdevteam/hberp/hberp.git develop') # 打包前端 # os.chdir('/home/hberp/hb_client') # os.system('npm run build:prod')