From a4f2b6eb5593eee3abac18269660adfd790d71f7 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 26 May 2025 15:26:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20batchlog=E5=88=9B=E5=BB=BA=E6=97=B6?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E5=9B=9E=E7=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/models.py | 8 +++++--- apps/wpm/services.py | 14 ++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/wpm/models.py b/apps/wpm/models.py index 43b5a3ae..67bff0fe 100644 --- a/apps/wpm/models.py +++ b/apps/wpm/models.py @@ -621,18 +621,20 @@ class BatchSt(BaseModel): unique_together = [("batch", "version")] @classmethod - def g_create(cls, batch:str, mio=None, handover=None, mlog=None, material_start=None, reuse_node=False): + def g_create(cls, batch:str, mio=None, handover=None, mlog=None, material_start=None, reuse_node=False, exclude_batchst_ids=[]): """ 创建新的批次 """ if mio is None and handover is None and mlog is None: try: - node = cls.objects.get(batch=batch) + node = cls.objects.exclude(id__in=exclude_batchst_ids).get(batch=batch) except cls.DoesNotExist: return cls.objects.create(batch=batch), True except cls.MultipleObjectsReturned: # 兼容性处理 - node = cls.objects.filter(batch=batch).order_by('-version').first() + node = cls.objects.filter(batch=batch).exclude(id__in=exclude_batchst_ids).order_by('-version').first() + if node is None: + raise ParseError(f"{node.batch}-该批次号本次操作不可引用") return node, False else: version = 1 diff --git a/apps/wpm/services.py b/apps/wpm/services.py index 7acb71bd..94ed0d87 100644 --- a/apps/wpm/services.py +++ b/apps/wpm/services.py @@ -175,14 +175,17 @@ def mlog_submit(mlog: Mlog, user: User, now: Union[datetime.datetime, None]): can_matoutIds = process.get_canout_mat_ids() # 建立关系链 m_outs = Mlogb.objects.filter(mlog=mlog, material_out__isnull=False) + exclude_batchst_ids = [] for item in m_outs: if item.mlogb_from and item.batch != item.mlogb_from.batch: - source, _ = BatchSt.g_create(batch=item.mlogb_from.batch) + source, _ = BatchSt.g_create(batch=item.mlogb_from.batch, exclude_batchst_ids=exclude_batchst_ids) target, _ = BatchSt.g_create(batch=item.batch, mlog=mlog, material_start=item.material_out) + exclude_batchst_ids.append(target.id) BatchLog.g_create(source= source, target=target, mlog=mlog) if item.mlogbw_from and item.batch != item.mlogbw_from.mlogb.batch: - source, _ = BatchSt.g_create(batch=item.mlogbw_from.mlogb.batch) + source, _ = BatchSt.g_create(batch=item.mlogbw_from.mlogb.batch, exclude_batchst_ids=exclude_batchst_ids) target, _ = BatchSt.g_create(batch=item.batch, mlog=mlog, material_start=item.material_out) + exclude_batchst_ids.append(target.id) BatchLog.g_create(source=source, target=target, mlog=mlog) if material_in or is_fix: # 需要进行车间库存管理 @@ -746,6 +749,7 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime, raise ParseError("合并批次时请提供新批次号") new_target = None + exclude_batchst_ids = [] mids = [] for item in handoverb_list: wmId, xcount, handover_or_b = item @@ -756,17 +760,19 @@ def handover_submit(handover:Handover, user: User, now: Union[datetime.datetime, # 合并为新批 if mtype == Handover.H_MERGE: - source, _ = BatchSt.g_create(batch=wm_from.batch) + 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") elif mtype == Handover.H_DIV: if handover.wm is None: raise ParseError('拆批请选择车间库存') - source, _ = BatchSt.g_create(batch=handover.wm.batch) + source, _ = BatchSt.g_create(batch=handover.wm.batch, exclude_batchst_ids=exclude_batchst_ids) batch = handover_or_b.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") else: batch = wm_from.batch