feat: handover拆批时校验批次号是否可用

This commit is contained in:
caoqianming 2025-05-30 09:07:17 +08:00
parent 45e02eae5f
commit f689b7609c
1 changed files with 18 additions and 14 deletions

View File

@ -738,19 +738,26 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
recive_mgroup = handover.recive_mgroup recive_mgroup = handover.recive_mgroup
recive_dept = handover.recive_dept recive_dept = handover.recive_dept
batches = []
new_batch = handover.new_batch new_batch = handover.new_batch
if new_batch and mtype != Handover.H_MERGE: if new_batch and mtype != Handover.H_MERGE:
raise ParseError("只有合并时才能提供新批次号") raise ParseError("只有合并时才能提供新批次号")
batches = []
mids = []
exclude_batchst_ids = []
if mtype == Handover.H_MERGE: if mtype == Handover.H_MERGE:
if new_batch: if new_batch:
batches = [new_batch] batches = [new_batch]
else: else:
raise ParseError("合并批次时请提供新批次号") raise ParseError("合并批次时请提供新批次号")
target_b, _ = BatchSt.g_create(batch=new_batch, handover=handover, material_start=material)
new_target = None exclude_batchst_ids.append(target_b.id)
exclude_batchst_ids = [] elif mtype == Handover.H_DIV:
mids = [] if handover.wm is None:
raise ParseError('拆批请选择车间库存')
batches_to_limit = BatchLog.batches_to(batch=handover.wm.batch)
source_b, _ = BatchSt.g_create(batch=handover.wm.batch)
for item in handoverb_list: for item in handoverb_list:
wmId, xcount, handover_or_b = item wmId, xcount, handover_or_b = item
if xcount <= 0: if xcount <= 0:
@ -761,19 +768,16 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime,
# 合并为新批 # 合并为新批
if mtype == Handover.H_MERGE: if mtype == Handover.H_MERGE:
source, _ = BatchSt.g_create(batch=wm_from.batch, exclude_batchst_ids=exclude_batchst_ids) source, _ = BatchSt.g_create(batch=wm_from.batch, exclude_batchst_ids=exclude_batchst_ids)
batch = new_batch BatchLog.g_create(source=source, target=target_b, handover=handover, relation_type="merge")
if new_target is None:
new_target, _ = BatchSt.g_create(batch=batch, handover=handover, material_start=material)
exclude_batchst_ids.append(new_target.id)
BatchLog.g_create(source=source, target=new_target, handover=handover, relation_type="merge")
elif mtype == Handover.H_DIV: elif mtype == Handover.H_DIV:
if handover.wm is None:
raise ParseError('拆批请选择车间库存')
source, _ = BatchSt.g_create(batch=handover.wm.batch, exclude_batchst_ids=exclude_batchst_ids)
batch = handover_or_b.batch batch = handover_or_b.batch
if batch in batches_to_limit:
raise ParseError(f'{batch} 不在可拆批次中')
else:
batches_to_limit.append(batch)
target, _ = BatchSt.g_create(batch=batch, handover=handover, material_start=material) target, _ = BatchSt.g_create(batch=batch, handover=handover, material_start=material)
exclude_batchst_ids.append(target.id) exclude_batchst_ids.append(target.id)
BatchLog.g_create(source=source, target=target, handover=handover, relation_type="split") BatchLog.g_create(source=source_b, target=target, handover=handover, relation_type="split")
else: else:
batch = wm_from.batch batch = wm_from.batch
batches.append(batch) batches.append(batch)