From 0334035e77611823745681c3727e01174fa80694 Mon Sep 17 00:00:00 2001
From: Oliver Walters <oliver.henry.walters@gmail.com>
Date: Mon, 20 Apr 2020 01:09:37 +1000
Subject: [PATCH] Simplify StockItem serializer

- Some more work needed here to cut down on database hits
---
 InvenTree/InvenTree/static/script/inventree/stock.js |  1 +
 InvenTree/part/serializers.py                        | 10 ----------
 InvenTree/stock/serializers.py                       |  8 --------
 3 files changed, 1 insertion(+), 18 deletions(-)

diff --git a/InvenTree/InvenTree/static/script/inventree/stock.js b/InvenTree/InvenTree/static/script/inventree/stock.js
index 6956b0abfc..3fe11ed087 100644
--- a/InvenTree/InvenTree/static/script/inventree/stock.js
+++ b/InvenTree/InvenTree/static/script/inventree/stock.js
@@ -47,6 +47,7 @@ function loadStockTable(table, options) {
     // List of user-params which override the default filters
 
     options.params['part_detail'] = true;
+    options.params['location_detail'] = true;
 
     var params = options.params || {};
 
diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py
index 7ad1b83aa8..a7305dcb2e 100644
--- a/InvenTree/part/serializers.py
+++ b/InvenTree/part/serializers.py
@@ -54,14 +54,6 @@ class PartBriefSerializer(InvenTreeModelSerializer):
 
     url = serializers.CharField(source='get_absolute_url', read_only=True)
     thumbnail = serializers.CharField(source='get_thumbnail_url', read_only=True)
-
-    @staticmethod
-    def setup_eager_loading(queryset):
-        queryset = queryset.prefetch_related('category')
-        queryset = queryset.prefetch_related('stock_items')
-        queryset = queryset.prefetch_related('bom_items')
-        queryset = queryset.prefetch_related('builds')
-        return queryset
     
     class Meta:
         model = Part
@@ -70,8 +62,6 @@ class PartBriefSerializer(InvenTreeModelSerializer):
             'url',
             'full_name',
             'description',
-            'total_stock',
-            'available_stock',
             'thumbnail',
             'active',
             'assembly',
diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py
index a7b51672c4..a4de99040a 100644
--- a/InvenTree/stock/serializers.py
+++ b/InvenTree/stock/serializers.py
@@ -77,13 +77,11 @@ class StockItemSerializer(InvenTreeModelSerializer):
     
     part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
     location_detail = LocationBriefSerializer(source='location', many=False, read_only=True)
-    supplier_part_detail = SupplierPartSerializer(source='supplier_part', many=False, read_only=True)
 
     def __init__(self, *args, **kwargs):
 
         part_detail = kwargs.pop('part_detail', False)
         location_detail = kwargs.pop('location_detail', False)
-        supplier_detail = kwargs.pop('supplier_detail', False)
 
         super(StockItemSerializer, self).__init__(*args, **kwargs)
 
@@ -93,9 +91,6 @@ class StockItemSerializer(InvenTreeModelSerializer):
         if location_detail is not True:
             self.fields.pop('location_detail')
 
-        if supplier_detail is not True:
-            self.fields.pop('supplier_part_detail')
-
     class Meta:
         model = StockItem
         fields = [
@@ -111,12 +106,9 @@ class StockItemSerializer(InvenTreeModelSerializer):
             'quantity',
             'serial',
             'supplier_part',
-            'supplier_part_detail',
             'status',
             'status_text',
-            #'tracking_items',
             'uid',
-            #'url',
         ]
 
         """ These fields are read-only in this context.