diff --git a/apps/inm/views.py b/apps/inm/views.py index 31af8866..7a906f6a 100644 --- a/apps/inm/views.py +++ b/apps/inm/views.py @@ -254,13 +254,18 @@ class MIOItemViewSet(ListModelMixin, BulkCreateModelMixin, BulkDestroyModelMixin batch = ins.batch material = ins.material warehouse = ins.warehouse - mb = MaterialBatch.objects.get( - material=material, batch=batch, warehouse=warehouse) - count_new = mb.count - count_notok - if count_new < 0: - raise ParseError('库存扣减失败,请确认!') - mb.count = count_new - mb.save() + try: + mb = MaterialBatch.objects.get( + material=material, batch=batch, warehouse=warehouse) + count_new = mb.count - count_notok + if count_new < 0: + raise ParseError('库存扣减失败,请确认!') + mb.count = count_new + mb.save() + except MaterialBatch.DoesNotExist: + # 库存不存在已被消耗了 + if count_notok != 0: + raise ParseError('库存已全消耗!') return Response() @action(methods=['post'], detail=True, perms_map={'post': 'mioitem.test'}, serializer_class=MIOItemPurInTestSerializer)