From 150c68e65b68f860e08d8c4a233c7cf7cca5c267 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 13 May 2019 18:52:54 +1000 Subject: [PATCH] Bug fix - Turns out 'item_count' was actually used for something (that I wrote... recently...) --- InvenTree/InvenTree/views.py | 4 ++-- InvenTree/stock/models.py | 7 +++++++ InvenTree/stock/tests.py | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 9331cdf215..b837b3da59 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -43,7 +43,7 @@ class TreeSerializer(views.APIView): 'pk': item.id, 'text': item.name, 'href': item.get_absolute_url(), - 'tags': [item.stock_item_count], + 'tags': [item.item_count], } if item.has_children: @@ -66,7 +66,7 @@ class TreeSerializer(views.APIView): for item in top_items: nodes.append(self.itemToJson(item)) - top_count += item.stock_item_count + top_count += item.item_count top = { 'pk': None, diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index cbc64f42ab..950d6237dd 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -55,6 +55,13 @@ class StockLocation(InvenTreeTree): return StockItem.objects.filter(location__in=self.getUniqueChildren()).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 + @receiver(pre_delete, sender=StockLocation, dispatch_uid='stocklocation_delete_log') def before_delete_stock_location(sender, instance, using, **kwargs): diff --git a/InvenTree/stock/tests.py b/InvenTree/stock/tests.py index 21242aad9b..417c995b6c 100644 --- a/InvenTree/stock/tests.py +++ b/InvenTree/stock/tests.py @@ -79,7 +79,7 @@ class StockTest(TestCase): # Drawer 3 should have three stock items self.assertEqual(self.drawer3.stock_items.count(), 3) - self.assertEqual(self.drawer3.stock_item_count, 3) + self.assertEqual(self.drawer3.item_count, 3) def test_stock_count(self): part = Part.objects.get(pk=1)