Merge pull request #1321 from SchrodingersGat/next-build-order

Logic fix for "guessing" next build order number
This commit is contained in:
Oliver 2021-02-18 16:08:58 +11:00 committed by GitHub
commit 8cb3d6ab0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -379,24 +379,32 @@ class Build(MPTTModel):
if cls.objects.count() == 0: if cls.objects.count() == 0:
return None return None
build = cls.objects.last() # Extract the "most recent" build order reference
builds = cls.objects.exclude(reference=None)
if not builds.exists():
return None
build = builds.last()
ref = build.reference ref = build.reference
if not ref: if not ref:
return None return None
tries = set() tries = set(ref)
new_ref = ref
while 1: while 1:
new_ref = increment(ref) new_ref = increment(new_ref)
if new_ref in tries: if new_ref in tries:
# We are potentially stuck in a loop - simply return the original reference # We are potentially stuck in a loop - simply return the original reference
return ref return ref
# Check if the existing build reference exists
if cls.objects.filter(reference=new_ref).exists(): if cls.objects.filter(reference=new_ref).exists():
tries.add(new_ref) tries.add(new_ref)
new_ref = increment(new_ref)
else: else:
break break