Simplify StockItem serializer

- Some more work needed here to cut down on database hits
This commit is contained in:
Oliver Walters 2020-04-20 01:09:37 +10:00
parent 4b1b9df193
commit 0334035e77
3 changed files with 1 additions and 18 deletions

View File

@ -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 || {};

View File

@ -55,14 +55,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
fields = [
@ -70,8 +62,6 @@ class PartBriefSerializer(InvenTreeModelSerializer):
'url',
'full_name',
'description',
'total_stock',
'available_stock',
'thumbnail',
'active',
'assembly',

View File

@ -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.