From f57604492b9a516a8685fa0ac18c37c7f0b4b5a7 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 21 Mar 2025 17:54:50 +0800 Subject: [PATCH] fix: batchst create bug --- apps/wpm/models.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/apps/wpm/models.py b/apps/wpm/models.py index 4d1aedb1..713215ec 100644 --- a/apps/wpm/models.py +++ b/apps/wpm/models.py @@ -589,13 +589,11 @@ class BatchSt(BaseModel): """ 创建新的批次 """ - try: - BatchSt.objects.get(batch=batch) - raise ParseError(f"{batch} 该批号不可使用") - except BatchSt.DoesNotExist: - if mio is None and handover is None and mlog is None: - raise ParseError("mio or handover or mlog must be provided") - BatchSt.objects.create(batch=batch, mio=mio, handover=handover, mlog=mlog) + if BatchSt.objects.filter(batch=batch).exists(): + raise ParseError(f"{batch} 该批号已存在不可用") + if mio is None and handover is None and mlog is None: + raise ParseError("mio or handover or mlog must be provided") + BatchSt.objects.create(batch=batch, mio=mio, handover=handover, mlog=mlog)