2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-14 11:05:41 +00:00

Improved speed of stock tree

This commit is contained in:
Oliver Walters
2019-06-18 00:09:42 +10:00
parent a796b984ff
commit 642660d76e
3 changed files with 20 additions and 12 deletions

View File

@ -49,19 +49,23 @@ class StockLocation(InvenTreeTree):
}
)
@property
def stock_item_count(self):
def stock_item_count(self, cascade=True):
""" Return the number of StockItem objects which live in or under this category
"""
return StockItem.objects.filter(location__in=self.getUniqueChildren()).count()
if cascade:
query = StockItem.objects.filter(location__in=self.getUniqueChildren())
else:
query = StockItem.objects.filter(location=self)
return query.count()
@property
def item_count(self):
""" Simply returns the number of stock items in this location.
Required for tree view serializer.
"""
return self.stock_item_count
return self.stock_item_count()
@receiver(pre_delete, sender=StockLocation, dispatch_uid='stocklocation_delete_log')