库存半成品列表根据出入库记录变动
This commit is contained in:
parent
bd8b458b5d
commit
ace7d222c8
|
|
@ -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,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -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)
|
material = models.ForeignKey(Material, verbose_name='物料类型', on_delete=models.CASCADE)
|
||||||
warehouse = models.ForeignKey(WareHouse, on_delete=models.CASCADE, verbose_name='所在仓库')
|
warehouse = models.ForeignKey(WareHouse, on_delete=models.CASCADE, verbose_name='所在仓库')
|
||||||
batch = models.CharField('所属批次号', max_length=100, default='')
|
batch = models.CharField('所属批次号', max_length=100, default='')
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from django.db.models.signals import post_save
|
from django.db.models.signals import post_save
|
||||||
from django.dispatch import receiver
|
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):
|
def update_inm(instance:FIFO, type:int=1):
|
||||||
|
|
@ -23,6 +23,19 @@ def update_inm(instance:FIFO, type:int=1):
|
||||||
o2.save()
|
o2.save()
|
||||||
material.count = material.count + i.count
|
material.count = material.count + i.count
|
||||||
material.save()
|
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]: # 生产领料
|
elif instance.type in [FIFO.FIFO_TYPE_DO_OUT]: # 生产领料
|
||||||
# 更新相关表
|
# 更新相关表
|
||||||
for i in FIFOItem.objects.filter(fifo=instance):
|
for i in FIFOItem.objects.filter(fifo=instance):
|
||||||
|
|
@ -37,3 +50,7 @@ def update_inm(instance:FIFO, type:int=1):
|
||||||
material.count = material.count - i.count
|
material.count = material.count - i.count
|
||||||
material.save()
|
material.save()
|
||||||
|
|
||||||
|
# 删除IProduct
|
||||||
|
numbers = FIFOItemProduct.objects.filter(fifoitem=i).values_list('number', flat=True)
|
||||||
|
IProduct.objects.filter(number__in=numbers).delete()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,8 @@ class SubProductionPlan(CommonAModel):
|
||||||
start_date_real = models.DateField('实际开工日期', null=True, blank=True)
|
start_date_real = models.DateField('实际开工日期', null=True, blank=True)
|
||||||
end_date_real = models.DateField('实际完工日期', null=True, blank=True)
|
end_date_real = models.DateField('实际完工日期', null=True, blank=True)
|
||||||
is_picked = models.BooleanField('是否已领料', default=False)
|
is_picked = models.BooleanField('是否已领料', default=False)
|
||||||
|
|
||||||
|
# wproducts = models.JSONField('半成品表', default=list, blank=True)
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = '子生产计划'
|
verbose_name = '子生产计划'
|
||||||
verbose_name_plural = verbose_name
|
verbose_name_plural = verbose_name
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ def update_subplan_main(sender, instance, created, **kwargs):
|
||||||
subplan.main_product = instance.material
|
subplan.main_product = instance.material
|
||||||
subplan.main_count = instance.count
|
subplan.main_count = instance.count
|
||||||
subplan.main_count_real = instance.count_real
|
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.state = 4
|
||||||
subplan.save()
|
subplan.save()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class WMaterial(BaseModel):
|
||||||
|
|
||||||
class WProduct(CommonAModel):
|
class WProduct(CommonAModel):
|
||||||
"""
|
"""
|
||||||
半成品/成品
|
动态半成品/成品表
|
||||||
"""
|
"""
|
||||||
WPR_ACT_STATE_DOING = 1
|
WPR_ACT_STATE_DOING = 1
|
||||||
WPR_ACT_STATE_TOTEST = 2
|
WPR_ACT_STATE_TOTEST = 2
|
||||||
|
|
@ -45,7 +45,6 @@ class WProduct(CommonAModel):
|
||||||
production_plan = models.ForeignKey(ProductionPlan, verbose_name='关联主生产计划', on_delete=models.CASCADE)
|
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)
|
warehouse = models.ForeignKey(WareHouse, verbose_name='所在仓库', on_delete=models.SET_NULL, null=True, blank=True)
|
||||||
|
|
||||||
|
|
||||||
class Operation(CommonAModel):
|
class Operation(CommonAModel):
|
||||||
"""
|
"""
|
||||||
生产操作
|
生产操作
|
||||||
|
|
|
||||||
|
|
@ -44,13 +44,25 @@ class WPlanViewSet(ListModelMixin, GenericViewSet):
|
||||||
"""
|
"""
|
||||||
领半成品
|
领半成品
|
||||||
"""
|
"""
|
||||||
# if request.method=='GET'
|
sp = self.get_object()
|
||||||
# subplan = self.get_object()
|
if request.method=='GET':
|
||||||
# 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']])
|
mIds = SubProductionProgress.objects.filter(type=SubprodctionMaterial.SUB_MA_TYPE_IN,
|
||||||
# pass
|
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)
|
@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.number = 'WP-'+ranstr(7)
|
||||||
wproduct.save()
|
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,
|
instance = SubProductionProgress.objects.get(subproduction_plan=wproduct.subproduction_plan,
|
||||||
is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT)
|
is_main=True, type=SubprodctionMaterial.SUB_MA_TYPE_OUT)
|
||||||
instance.count_real = main_count
|
instance.count_real = instance.count_real + 1 # 这个地方可能会有问题
|
||||||
instance.save()
|
instance.save()
|
||||||
else:# 如果不合格
|
else:# 如果不合格
|
||||||
pass
|
pass
|
||||||
|
|
@ -235,17 +246,6 @@ class WProductViewSet(ListModelMixin, GenericViewSet):
|
||||||
ip['material'] = material
|
ip['material'] = material
|
||||||
ips.append(FIFOItemProduct(**ip))
|
ips.append(FIFOItemProduct(**ip))
|
||||||
FIFOItemProduct.objects.bulk_create(ips)
|
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)
|
update_inm(fifo)
|
||||||
wproduct.act_state=WProduct.WPR_ACT_STATE_INM
|
wproduct.act_state=WProduct.WPR_ACT_STATE_INM
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue