mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #1321 from SchrodingersGat/next-build-order
Logic fix for "guessing" next build order number
This commit is contained in:
commit
8cb3d6ab0a
@ -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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user