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"]