diff --git a/hb_server/apps/inm/migrations/0017_alter_iproduct_number.py b/hb_server/apps/inm/migrations/0017_alter_iproduct_number.py new file mode 100644 index 0000000..0e3931c --- /dev/null +++ b/hb_server/apps/inm/migrations/0017_alter_iproduct_number.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.6 on 2021-11-17 06:38 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('inm', '0016_auto_20211112_1124'), + ] + + operations = [ + migrations.AlterField( + model_name='iproduct', + name='number', + field=models.CharField(default=1, max_length=50, unique=True, verbose_name='物品编号'), + preserve_default=False, + ), + ] diff --git a/hb_server/apps/inm/models.py b/hb_server/apps/inm/models.py index c3902bf..57e3e17 100644 --- a/hb_server/apps/inm/models.py +++ b/hb_server/apps/inm/models.py @@ -97,7 +97,7 @@ class IProduct(BaseModel): """ 具体产品条目 """ - number = models.CharField('物品编号', unique=True, null=True, blank=True, max_length=50) + number = models.CharField('物品编号', unique=True, max_length=50) material = models.ForeignKey(Material, verbose_name='物料类型', on_delete=models.CASCADE) warehouse = models.ForeignKey(WareHouse, on_delete=models.CASCADE, verbose_name='所在仓库') batch = models.CharField('所属批次号', max_length=100, default='') diff --git a/hb_server/apps/inm/signals.py b/hb_server/apps/inm/signals.py index 66870a4..79d5a19 100644 --- a/hb_server/apps/inm/signals.py +++ b/hb_server/apps/inm/signals.py @@ -1,7 +1,7 @@ from django.db.models.signals import post_save from django.dispatch import receiver -from apps.inm.models import FIFOItemProduct, Inventory, MaterialBatch, FIFO, FIFOItem +from apps.inm.models import FIFOItemProduct, IProduct, Inventory, MaterialBatch, FIFO, FIFOItem def update_inm(instance:FIFO, type:int=1): @@ -23,6 +23,19 @@ def update_inm(instance:FIFO, type:int=1): o2.save() material.count = material.count + i.count material.save() + + # 创建IProduct + ips2 = [] + for m in FIFOItemProduct.objects.filter(fifoitem=i): + ip = {} + ip['warehouse'] = warehouse + ip['batch'] = i.batch + ip['wproduct'] = m.wproduct + ip['number'] = m.number + ip['material'] = m.material + ips2.append(IProduct(**ip)) + IProduct.objects.bulk_create(ips2) + elif instance.type in [FIFO.FIFO_TYPE_DO_OUT]: # 生产领料 # 更新相关表 for i in FIFOItem.objects.filter(fifo=instance): @@ -36,4 +49,8 @@ def update_inm(instance:FIFO, type:int=1): o2.save() material.count = material.count - i.count material.save() + + # 删除IProduct + numbers = FIFOItemProduct.objects.filter(fifoitem=i).values_list('number', flat=True) + IProduct.objects.filter(number__in=numbers).delete() diff --git a/hb_server/apps/pm/models.py b/hb_server/apps/pm/models.py index bc59ec9..ddddd78 100644 --- a/hb_server/apps/pm/models.py +++ b/hb_server/apps/pm/models.py @@ -57,6 +57,8 @@ class SubProductionPlan(CommonAModel): start_date_real = models.DateField('实际开工日期', null=True, blank=True) end_date_real = models.DateField('实际完工日期', null=True, blank=True) is_picked = models.BooleanField('是否已领料', default=False) + + # wproducts = models.JSONField('半成品表', default=list, blank=True) class Meta: verbose_name = '子生产计划' verbose_name_plural = verbose_name diff --git a/hb_server/apps/pm/signals.py b/hb_server/apps/pm/signals.py index 9d6cd6c..b07a67c 100644 --- a/hb_server/apps/pm/signals.py +++ b/hb_server/apps/pm/signals.py @@ -13,7 +13,7 @@ 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 subplan.main_count == instance.count_real: + if subplan.main_count >= instance.count_real: subplan.state = 4 subplan.save() diff --git a/hb_server/apps/wpm/models.py b/hb_server/apps/wpm/models.py index 83dfcf1..7424783 100644 --- a/hb_server/apps/wpm/models.py +++ b/hb_server/apps/wpm/models.py @@ -20,7 +20,7 @@ class WMaterial(BaseModel): class WProduct(CommonAModel): """ - 半成品/成品 + 动态半成品/成品表 """ WPR_ACT_STATE_DOING = 1 WPR_ACT_STATE_TOTEST = 2 @@ -45,7 +45,6 @@ class WProduct(CommonAModel): 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) - class Operation(CommonAModel): """ 生产操作 diff --git a/hb_server/apps/wpm/views.py b/hb_server/apps/wpm/views.py index d81c071..7a5f9c3 100644 --- a/hb_server/apps/wpm/views.py +++ b/hb_server/apps/wpm/views.py @@ -44,13 +44,25 @@ class WPlanViewSet(ListModelMixin, GenericViewSet): """ 领半成品 """ - # if request.method=='GET' - # subplan = self.get_object() - # serializer= PickHalfSerializer(data=request.data) - # serializer.is_valid(raise_exception=True) - # vdata = serializer.data - # wps = WProduct.objects.filter(pk__in=[x for x in vdata['wproducts']]) - # pass + sp = self.get_object() + if request.method=='GET': + """ + 领半成品 + """ + mIds = SubProductionProgress.objects.filter(type=SubprodctionMaterial.SUB_MA_TYPE_IN, + material__type=Material.MA_TYPE_HALFGOOD).values_list('material', flat=True) + queyset = WProduct.objects.filter(is_hidden=False, m_state__in=mIds, act_state=WProduct.WPR_ACT_STATE_OK) + return Response(WProductListSerializer(instance=queyset, many=True).data) + elif request.method=='POST': + serializer= PickHalfSerializer(data=request.data) + serializer.is_valid(raise_exception=True) + vdata = serializer.data + wps = WProduct.objects.filter(pk__in=[x for x in vdata['wproducts']]) + first_step = Step.objects.get(pk=sp.steps[0].id) + wps.update(p_state=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) + return Response() @action(methods=['post'], detail=True, perms_map={'post':'*'}, serializer_class=WplanPutInSerializer) @@ -184,11 +196,10 @@ class WProductViewSet(ListModelMixin, GenericViewSet): wproduct.number = 'WP-'+ranstr(7) wproduct.save() # 更新子计划状态 - # 获取该子计划主产品数, 更新进度 - main_count = WProduct.objects.filter(subproduction_plan=wproduct.subproduction_plan, act_state=WProduct.WPR_ACT_STATE_OK).count() + # 更新子计划主产品数 instance = SubProductionProgress.objects.get(subproduction_plan=wproduct.subproduction_plan, is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT) - instance.count_real = main_count + instance.count_real = instance.count_real + 1 # 这个地方可能会有问题 instance.save() else:# 如果不合格 pass @@ -235,17 +246,6 @@ class WProductViewSet(ListModelMixin, GenericViewSet): ip['material'] = material ips.append(FIFOItemProduct(**ip)) FIFOItemProduct.objects.bulk_create(ips) - # 创建IProduct - ips2 = [] - for i in [wproduct]: - ip = {} - ip['warehouse'] = warehouse - ip['batch'] = batch - ip['wproduct'] = i - ip['number'] = i.number - ip['material'] = material - ips2.append(IProduct(**ip)) - IProduct.objects.bulk_create(ips2) # 更新库存并修改半成品进行状态 update_inm(fifo) wproduct.act_state=WProduct.WPR_ACT_STATE_INM