feat: 合批时校验批次是否已存在
This commit is contained in:
parent
57459cc7dc
commit
07b2df1fd0
|
|
@ -706,12 +706,15 @@ class BatchSt(BaseModel):
|
|||
unique_together = [("batch", "version")]
|
||||
|
||||
@classmethod
|
||||
def g_create(cls, batch:str, mio=None, mioitem=None, handover=None, mlog=None, material_start=None, check_mat_start=False, exclude_batchst_ids=[]):
|
||||
def g_create(cls, batch:str, mio=None, mioitem=None, handover=None, mlog=None, material_start=None, check_mat_start=False, exclude_batchst_ids=[], check_batch_exist=False):
|
||||
"""
|
||||
创建新的批次
|
||||
"""
|
||||
if mioitem:
|
||||
mio = mioitem.mio
|
||||
if check_batch_exist:
|
||||
if cls.objects.filter(batch=batch).exclude(id__in=exclude_batchst_ids).exists():
|
||||
raise ParseError(f"{batch}-该批次号已存在不可使用")
|
||||
node, created = cls.safe_get_or_create(batch=batch, version=1, defaults={
|
||||
"mio":mio, "mioitem":mioitem, "handover":handover, "mlog":mlog, "material_start":material_start})
|
||||
if not created and check_mat_start:
|
||||
|
|
|
|||
|
|
@ -727,12 +727,15 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
|
|||
batches = []
|
||||
mids = []
|
||||
exclude_batchst_ids = []
|
||||
check_batch_exist = False
|
||||
if mtype == Handover.H_MERGE:
|
||||
if new_batch:
|
||||
batches = [new_batch]
|
||||
else:
|
||||
raise ParseError("合并批次时请提供新批次号")
|
||||
target_b, _ = BatchSt.g_create(batch=new_batch, handover=handover, material_start=material)
|
||||
if handover.new_wm is None:
|
||||
check_batch_exist = True
|
||||
target_b, _ = BatchSt.g_create(batch=new_batch, handover=handover, material_start=material, check_batch_exist=check_batch_exist)
|
||||
exclude_batchst_ids.append(target_b.id)
|
||||
elif mtype == Handover.H_DIV:
|
||||
if handover.wm is None:
|
||||
|
|
@ -761,6 +764,7 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
|
|||
batches_to_limit.append(batch)
|
||||
target, _ = BatchSt.g_create(batch=batch, handover=handover, material_start=material)
|
||||
exclude_batchst_ids.append(target.id)
|
||||
# 这里暂时忽略check_batch_exist,因为拆批一般不会重复
|
||||
BatchLog.g_create(source=source_b, target=target, handover=handover, relation_type="split")
|
||||
else:
|
||||
batch = wm_from.batch
|
||||
|
|
|
|||
Loading…
Reference in New Issue