mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Simplify StockItem serializer
- Some more work needed here to cut down on database hits
This commit is contained in:
parent
4b1b9df193
commit
0334035e77
@ -47,6 +47,7 @@ function loadStockTable(table, options) {
|
|||||||
// List of user-params which override the default filters
|
// List of user-params which override the default filters
|
||||||
|
|
||||||
options.params['part_detail'] = true;
|
options.params['part_detail'] = true;
|
||||||
|
options.params['location_detail'] = true;
|
||||||
|
|
||||||
var params = options.params || {};
|
var params = options.params || {};
|
||||||
|
|
||||||
|
@ -54,14 +54,6 @@ class PartBriefSerializer(InvenTreeModelSerializer):
|
|||||||
|
|
||||||
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
url = serializers.CharField(source='get_absolute_url', read_only=True)
|
||||||
thumbnail = serializers.CharField(source='get_thumbnail_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:
|
class Meta:
|
||||||
model = Part
|
model = Part
|
||||||
@ -70,8 +62,6 @@ class PartBriefSerializer(InvenTreeModelSerializer):
|
|||||||
'url',
|
'url',
|
||||||
'full_name',
|
'full_name',
|
||||||
'description',
|
'description',
|
||||||
'total_stock',
|
|
||||||
'available_stock',
|
|
||||||
'thumbnail',
|
'thumbnail',
|
||||||
'active',
|
'active',
|
||||||
'assembly',
|
'assembly',
|
||||||
|
@ -77,13 +77,11 @@ class StockItemSerializer(InvenTreeModelSerializer):
|
|||||||
|
|
||||||
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
|
part_detail = PartBriefSerializer(source='part', many=False, read_only=True)
|
||||||
location_detail = LocationBriefSerializer(source='location', 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):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
||||||
part_detail = kwargs.pop('part_detail', False)
|
part_detail = kwargs.pop('part_detail', False)
|
||||||
location_detail = kwargs.pop('location_detail', False)
|
location_detail = kwargs.pop('location_detail', False)
|
||||||
supplier_detail = kwargs.pop('supplier_detail', False)
|
|
||||||
|
|
||||||
super(StockItemSerializer, self).__init__(*args, **kwargs)
|
super(StockItemSerializer, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
@ -93,9 +91,6 @@ class StockItemSerializer(InvenTreeModelSerializer):
|
|||||||
if location_detail is not True:
|
if location_detail is not True:
|
||||||
self.fields.pop('location_detail')
|
self.fields.pop('location_detail')
|
||||||
|
|
||||||
if supplier_detail is not True:
|
|
||||||
self.fields.pop('supplier_part_detail')
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = StockItem
|
model = StockItem
|
||||||
fields = [
|
fields = [
|
||||||
@ -111,12 +106,9 @@ class StockItemSerializer(InvenTreeModelSerializer):
|
|||||||
'quantity',
|
'quantity',
|
||||||
'serial',
|
'serial',
|
||||||
'supplier_part',
|
'supplier_part',
|
||||||
'supplier_part_detail',
|
|
||||||
'status',
|
'status',
|
||||||
'status_text',
|
'status_text',
|
||||||
#'tracking_items',
|
|
||||||
'uid',
|
'uid',
|
||||||
#'url',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
""" These fields are read-only in this context.
|
""" These fields are read-only in this context.
|
||||||
|
Loading…
Reference in New Issue
Block a user