From c6222c65f655b6e9f530f89b2d531c53d5931720 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Sun, 7 Apr 2024 18:33:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8D=8A=E6=88=90=E5=93=81=E6=A3=80?= =?UTF-8?q?=E9=AA=8C=E6=9C=89=E5=85=B3=E5=BA=93=E5=AD=98=E6=B6=88=E8=80=97?= =?UTF-8?q?=E5=AE=8C=E7=9A=84=E9=80=BB=E8=BE=91=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/inm/views.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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)