fix: batchst reuse_node逻辑完善

This commit is contained in:
caoqianming 2025-05-29 09:39:04 +08:00
parent 82958e047b
commit 49efafcaff
1 changed files with 9 additions and 2 deletions

View File

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