def getNextOrderNumber(cls): """ Try to predict the next order-number """ if cls.objects.count() == 0: return None # We will assume that the latest pk has the highest PO number order = cls.objects.last() ref = order.reference if not ref: return None tries = set() tries.add(ref) while 1: new_ref = increment(ref) if new_ref in tries: # We are in a looping situation - simply return the original one return ref # Check that the new ref does not exist in the database if cls.objects.filter(reference=new_ref).exists(): tries.add(new_ref) new_ref = increment(new_ref) else: break return new_ref
def getNextBuildNumber(cls): """ Try to predict the next Build Order reference: """ if cls.objects.count() == 0: return None build = cls.objects.last() ref = build.reference if not ref: return None tries = set() while 1: new_ref = increment(ref) if new_ref in tries: # We are potentially stuck in a loop - simply return the original reference return ref if cls.objects.filter(reference=new_ref).exists(): tries.add(new_ref) new_ref = increment(new_ref) else: break return new_ref
def get_next_build_number(): """ Returns the next available BuildOrder reference number """ if Build.objects.count() == 0: return '0001' build = Build.objects.exclude(reference=None).last() attempts = set([build.reference]) reference = build.reference while 1: reference = increment(reference) if reference in attempts: # Escape infinite recursion return reference if Build.objects.filter(reference=reference).exists(): attempts.add(reference) else: break return reference
def get_next_so_number(): """ Returns the next available SalesOrder reference number """ if SalesOrder.objects.count() == 0: return order = SalesOrder.objects.exclude(reference=None).last() attempts = set([order.reference]) reference = order.reference while 1: reference = increment(reference) if reference in attempts: # Escape infinite recursion return reference if SalesOrder.objects.filter(reference=reference).exists(): attempts.add(reference) else: break return reference
def getNextBuildNumber(cls): """Try to predict the next Build Order reference.""" if cls.objects.count() == 0: return None # 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 if not ref: return None tries = set(ref) new_ref = ref while 1: new_ref = increment(new_ref) if new_ref in tries: # We are potentially stuck in a loop - simply return the original reference return ref # Check if the existing build reference exists if cls.objects.filter(reference=new_ref).exists(): tries.add(new_ref) else: break return new_ref
def get_next_po_number(): """ Returns the next available PurchaseOrder reference number """ if PurchaseOrder.objects.count() == 0: return '0001' order = PurchaseOrder.objects.exclude(reference=None).last() attempts = {order.reference} reference = order.reference while 1: reference = increment(reference) if reference in attempts: # Escape infinite recursion return reference if PurchaseOrder.objects.filter(reference=reference).exists(): attempts.add(reference) else: break return reference