From f689b7609cdcad296df485480a6a99e57f8ac64f Mon Sep 17 00:00:00 2001 From: caoqianming Date: Fri, 30 May 2025 09:07:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20handover=E6=8B=86=E6=89=B9=E6=97=B6?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E6=89=B9=E6=AC=A1=E5=8F=B7=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=8F=AF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/services.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 94ed0d87..a44431d6 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -738,19 +738,26 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime, recive_mgroup = handover.recive_mgroup recive_dept = handover.recive_dept - batches = [] + new_batch = handover.new_batch if new_batch and mtype != Handover.H_MERGE: raise ParseError("只有合并时才能提供新批次号") + + batches = [] + mids = [] + exclude_batchst_ids = [] if mtype == Handover.H_MERGE: if new_batch: batches = [new_batch] else: raise ParseError("合并批次时请提供新批次号") - - new_target = None - exclude_batchst_ids = [] - mids = [] + target_b, _ = BatchSt.g_create(batch=new_batch, handover=handover, material_start=material) + exclude_batchst_ids.append(target_b.id) + elif mtype == Handover.H_DIV: + 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: wmId, xcount, handover_or_b = item if xcount <= 0: @@ -761,19 +768,16 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime, # 合并为新批 if mtype == Handover.H_MERGE: source, _ = BatchSt.g_create(batch=wm_from.batch, exclude_batchst_ids=exclude_batchst_ids) - batch = new_batch - 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") + BatchLog.g_create(source=source, target=target_b, handover=handover, relation_type="merge") 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 + 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) 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: batch = wm_from.batch batches.append(batch)