diff --git a/hb_server/apps/wpm/migrations/0022_auto_20211123_1425.py b/hb_server/apps/wpm/migrations/0022_auto_20211123_1425.py new file mode 100644 index 0000000..bf6b8de --- /dev/null +++ b/hb_server/apps/wpm/migrations/0022_auto_20211123_1425.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.9 on 2021-11-23 06:25 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('wpm', '0021_auto_20211123_0945'), + ] + + operations = [ + migrations.RemoveField( + model_name='wproduct', + name='parent', + ), + migrations.AddField( + model_name='wproduct', + name='child', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='wpm.wproduct'), + ), + ] diff --git a/hb_server/apps/wpm/models.py b/hb_server/apps/wpm/models.py index ee835a1..db98eab 100644 --- a/hb_server/apps/wpm/models.py +++ b/hb_server/apps/wpm/models.py @@ -40,7 +40,7 @@ class WProduct(CommonAModel): act_state = models.IntegerField('进行状态', default=0, choices=act_state_choices) is_executed = models.BooleanField('子工序是否已执行', default=False) is_hidden = models.BooleanField('是否隐藏', default=False) - parent = models.JSONField('父', default=list, blank=True) + child = models.ForeignKey('self', blank=True, null=True, on_delete=models.CASCADE) 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') warehouse = models.ForeignKey(WareHouse, verbose_name='所在仓库', on_delete=models.SET_NULL, null=True, blank=True) diff --git a/hb_server/apps/wpm/views.py b/hb_server/apps/wpm/views.py index 2b2a75f..e200b2d 100644 --- a/hb_server/apps/wpm/views.py +++ b/hb_server/apps/wpm/views.py @@ -364,23 +364,22 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd for i in OperationMaterial.objects.filter(operation=op, type=SubprodctionMaterial.SUB_MA_TYPE_IN): # 更新车间物料 i_wmat = i.wmaterial - i_wmat.count = i_wmat.count- i['count'] + i_wmat.count = i_wmat.count- i.count i_wmat.save() # 更新子计划物料消耗情况 sp = i_wmat.subproduction_plan - sp.count_real = sp.count_real + i['count'] + 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, _ = 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.count_real = sp.count_real + i.count sp.save() # 更新动态产品表 if step.type == Step.STEP_TYPE_NOM: @@ -417,21 +416,25 @@ class OperationViewSet(ListModelMixin, RetrieveModelMixin, CreateModelMixin, Upd 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 + # 更新子计划进度 + instance = SubProductionProgress.objects.get(subproduction_plan=i.subproduction_plan, + is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT) + instance.count_real = instance.count_real + 1 # 这个地方可能会有问题,不够严谨 + instance.save() wproduct.save() + ows.update(is_hidden=True, child=wproduct)