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)