mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Improve query speed when calculating how many parts are on order
This commit is contained in:
parent
57123283f4
commit
41bbbdcd43
@ -919,7 +919,15 @@ 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().prefetch_related('purchase_order_line_items')])
|
orders = self.supplier_parts.filter(purchase_order_line_items__order__status__in=OrderStatus.OPEN).aggregate(
|
||||||
|
quantity=Sum('purchase_order_line_items__quantity'))
|
||||||
|
|
||||||
|
quantity = orders['quantity']
|
||||||
|
|
||||||
|
if quantity is None:
|
||||||
|
quantity = 0
|
||||||
|
|
||||||
|
return quantity
|
||||||
|
|
||||||
def get_parameters(self):
|
def get_parameters(self):
|
||||||
""" Return all parameters for this part, ordered by name """
|
""" Return all parameters for this part, ordered by name """
|
||||||
|
Loading…
Reference in New Issue
Block a user