Tweak the 'on_order' calculation

This commit is contained in:
Oliver Walters 2019-06-10 21:56:50 +10:00
parent 351c5fb7d0
commit 9efdd836f4
2 changed files with 2 additions and 2 deletions

View File

@ -327,7 +327,7 @@ class SupplierPart(models.Model):
if q is None or r is None: if q is None or r is None:
return 0 return 0
else: else:
return q - r return max(q-r, 0)
def purchase_orders(self): def purchase_orders(self):

View File

@ -809,7 +809,7 @@ class Part(models.Model):
def on_order(self): def on_order(self):
""" Return the total number of items on order for this part. """ """ Return the total number of items on order for this part. """
return sum([part.on_order() for part in self.supplier_parts.all()]) return sum([part.on_order() for part in self.supplier_parts.all().prefetch_related('purchase_order_line_items')])
def attach_file(instance, filename): def attach_file(instance, filename):