From 49efafcaffb83330593171442b71bb229af81145 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 29 May 2025 09:39:04 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20batchst=20reuse=5Fnode=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/wpm/models.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/wpm/models.py b/apps/wpm/models.py index 67bff0fe..ffeba063 100644 --- a/apps/wpm/models.py +++ b/apps/wpm/models.py @@ -643,9 +643,16 @@ class BatchSt(BaseModel): # 带有来源的批次获取,需检查批次号是否可用 if cls.objects.filter(batch=batch).exists(): if reuse_node: - node = cls.objects.filter(batch=batch, mio__isnull=False).order_by('-version').first() - if node.material_start is not None and node.material_start != material_start: + cls = cls.objects.filter(batch=batch) + node:BatchSt = (cls.objects.filter(mio__isnull=False)|cls.objects.filter( + material_start__isnull=True)).order_by('-version').first() + if node is None: raise ParseError(f"{batch}-该批次号因物料不同不可引用") + elif node.material_start is None: + node.material_start = material_start + node.save(update_fields = ["material_start"]) + elif node.material_start is not None and node.material_start != material_start: + raise ParseError(f"{batch}-该批次号因物料不同不可引用-{str(node.material_start)} vs {str(material_start)}") return node, False else: latest_version = BatchSt.objects.filter(batch=batch).aggregate(Max("version"))["version__max"]