mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Build API improvements (#3581)
* Improve build order lookup * Query efficiency improvements * Lazy load build allocation table * API defaults ensure consistent behaviour
This commit is contained in:
parent
89d5df4f1e
commit
b886e54709
@ -365,6 +365,7 @@ class BuildItemList(ListCreateAPI):
|
|||||||
kwargs['part_detail'] = str2bool(params.get('part_detail', False))
|
kwargs['part_detail'] = str2bool(params.get('part_detail', False))
|
||||||
kwargs['build_detail'] = str2bool(params.get('build_detail', False))
|
kwargs['build_detail'] = str2bool(params.get('build_detail', False))
|
||||||
kwargs['location_detail'] = str2bool(params.get('location_detail', False))
|
kwargs['location_detail'] = str2bool(params.get('location_detail', False))
|
||||||
|
kwargs['stock_detail'] = str2bool(params.get('stock_detail', True))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -372,13 +373,19 @@ class BuildItemList(ListCreateAPI):
|
|||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
"""Override the queryset method, to allow filtering by stock_item.part."""
|
"""Override the queryset method, to allow filtering by stock_item.part."""
|
||||||
query = BuildItem.objects.all()
|
queryset = BuildItem.objects.all()
|
||||||
|
|
||||||
query = query.select_related('stock_item__location')
|
queryset = queryset.select_related(
|
||||||
query = query.select_related('stock_item__part')
|
'bom_item',
|
||||||
query = query.select_related('stock_item__part__category')
|
'bom_item__sub_part',
|
||||||
|
'build',
|
||||||
|
'install_into',
|
||||||
|
'stock_item',
|
||||||
|
'stock_item__location',
|
||||||
|
'stock_item__part',
|
||||||
|
)
|
||||||
|
|
||||||
return query
|
return queryset
|
||||||
|
|
||||||
def filter_queryset(self, queryset):
|
def filter_queryset(self, queryset):
|
||||||
"""Customm query filtering for the BuildItem list."""
|
"""Customm query filtering for the BuildItem list."""
|
||||||
|
@ -856,6 +856,7 @@ class BuildItemSerializer(InvenTreeModelSerializer):
|
|||||||
build_detail = kwargs.pop('build_detail', False)
|
build_detail = kwargs.pop('build_detail', False)
|
||||||
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)
|
||||||
|
stock_detail = kwargs.pop('stock_detail', False)
|
||||||
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
@ -868,6 +869,9 @@ class BuildItemSerializer(InvenTreeModelSerializer):
|
|||||||
if not location_detail:
|
if not location_detail:
|
||||||
self.fields.pop('location_detail')
|
self.fields.pop('location_detail')
|
||||||
|
|
||||||
|
if not stock_detail:
|
||||||
|
self.fields.pop('stock_item_detail')
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
"""Serializer metaclass"""
|
"""Serializer metaclass"""
|
||||||
model = BuildItem
|
model = BuildItem
|
||||||
|
@ -455,7 +455,9 @@ function loadUntrackedStockTable() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadUntrackedStockTable();
|
onPanelLoad('allocate', function() {
|
||||||
|
loadUntrackedStockTable();
|
||||||
|
});
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -46,7 +46,6 @@ class LocationBriefSerializer(InvenTree.serializers.InvenTreeModelSerializer):
|
|||||||
class StockItemSerializerBrief(InvenTree.serializers.InvenTreeModelSerializer):
|
class StockItemSerializerBrief(InvenTree.serializers.InvenTreeModelSerializer):
|
||||||
"""Brief serializers for a StockItem."""
|
"""Brief serializers for a StockItem."""
|
||||||
|
|
||||||
location_name = serializers.CharField(source='location', read_only=True)
|
|
||||||
part_name = serializers.CharField(source='part.full_name', read_only=True)
|
part_name = serializers.CharField(source='part.full_name', read_only=True)
|
||||||
|
|
||||||
quantity = InvenTreeDecimalField()
|
quantity = InvenTreeDecimalField()
|
||||||
@ -60,7 +59,6 @@ class StockItemSerializerBrief(InvenTree.serializers.InvenTreeModelSerializer):
|
|||||||
'part_name',
|
'part_name',
|
||||||
'pk',
|
'pk',
|
||||||
'location',
|
'location',
|
||||||
'location_name',
|
|
||||||
'quantity',
|
'quantity',
|
||||||
'serial',
|
'serial',
|
||||||
'supplier_part',
|
'supplier_part',
|
||||||
|
@ -731,6 +731,7 @@ function loadBuildOrderAllocationTable(table, options={}) {
|
|||||||
options.params['part_detail'] = true;
|
options.params['part_detail'] = true;
|
||||||
options.params['build_detail'] = true;
|
options.params['build_detail'] = true;
|
||||||
options.params['location_detail'] = true;
|
options.params['location_detail'] = true;
|
||||||
|
options.params['stock_detail'] = true;
|
||||||
|
|
||||||
var filters = loadTableFilters('buildorderallocation');
|
var filters = loadTableFilters('buildorderallocation');
|
||||||
|
|
||||||
@ -1718,9 +1719,10 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
|
|||||||
field: 'location',
|
field: 'location',
|
||||||
title: '{% trans "Location" %}',
|
title: '{% trans "Location" %}',
|
||||||
formatter: function(value, row) {
|
formatter: function(value, row) {
|
||||||
if (row.stock_item_detail.location) {
|
|
||||||
var text = row.stock_item_detail.location_name;
|
if (row.location && row.location_detail) {
|
||||||
var url = `/stock/location/${row.stock_item_detail.location}/`;
|
var text = row.location_detail.name;
|
||||||
|
var url = `/stock/location/${row.location}/`;
|
||||||
|
|
||||||
return renderLink(text, url);
|
return renderLink(text, url);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user