feat: materialbatch也不进行物理删除

This commit is contained in:
caoqianming 2024-08-20 14:25:01 +08:00
parent 592e34c07e
commit 561c2a0c31
2 changed files with 5 additions and 4 deletions

View File

@ -87,7 +87,10 @@ class InmService:
material = i.material
warehouse = i.warehouse
mb, is_created = MaterialBatch.objects.get_or_create(
material=material, warehouse=warehouse, batch=i.batch, defaults={"material": material, "warehouse": warehouse, "count": 0, "batch": i.batch}
material=material,
warehouse=warehouse,
batch=i.batch,
defaults={"material": material, "warehouse": warehouse, "count": 0, "batch": i.batch}
)
if in_or_out == 1:
mb.count = mb.count + getattr(i, field)
@ -107,8 +110,6 @@ class InmService:
mb.count = mb.count - getattr(i, field)
if mb.count < 0:
raise ParseError("批次库存不足,操作失败")
elif mb.count == 0:
mb.delete()
else:
mb.save()
else:

View File

@ -45,7 +45,7 @@ class MaterialBatchViewSet(ListModelMixin, CustomGenericViewSet):
物料批次
"""
perms_map = {'get': '*'}
queryset = MaterialBatch.objects.all()
queryset = MaterialBatch.objects.filter(count__gt=0)
serializer_class = MaterialBatchSerializer
retrieve_serializer_class = MaterialBatchDetailSerializer
select_related_fields = ['warehouse', 'material']