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['build_detail'] = str2bool(params.get('build_detail', False))
|
||||
kwargs['location_detail'] = str2bool(params.get('location_detail', False))
|
||||
kwargs['stock_detail'] = str2bool(params.get('stock_detail', True))
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
@ -372,13 +373,19 @@ class BuildItemList(ListCreateAPI):
|
||||
|
||||
def get_queryset(self):
|
||||
"""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')
|
||||
query = query.select_related('stock_item__part')
|
||||
query = query.select_related('stock_item__part__category')
|
||||
queryset = queryset.select_related(
|
||||
'bom_item',
|
||||
'bom_item__sub_part',
|
||||
'build',
|
||||
'install_into',
|
||||
'stock_item',
|
||||
'stock_item__location',
|
||||
'stock_item__part',
|
||||
)
|
||||
|
||||
return query
|
||||
return queryset
|
||||
|
||||
def filter_queryset(self, queryset):
|
||||
"""Customm query filtering for the BuildItem list."""
|
||||
|
@ -856,6 +856,7 @@ class BuildItemSerializer(InvenTreeModelSerializer):
|
||||
build_detail = kwargs.pop('build_detail', False)
|
||||
part_detail = kwargs.pop('part_detail', False)
|
||||
location_detail = kwargs.pop('location_detail', False)
|
||||
stock_detail = kwargs.pop('stock_detail', False)
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
@ -868,6 +869,9 @@ class BuildItemSerializer(InvenTreeModelSerializer):
|
||||
if not location_detail:
|
||||
self.fields.pop('location_detail')
|
||||
|
||||
if not stock_detail:
|
||||
self.fields.pop('stock_item_detail')
|
||||
|
||||
class Meta:
|
||||
"""Serializer metaclass"""
|
||||
model = BuildItem
|
||||
|
@ -455,7 +455,9 @@ function loadUntrackedStockTable() {
|
||||
);
|
||||
}
|
||||
|
||||
loadUntrackedStockTable();
|
||||
onPanelLoad('allocate', function() {
|
||||
loadUntrackedStockTable();
|
||||
});
|
||||
|
||||
{% endif %}
|
||||
|
||||
|
@ -46,7 +46,6 @@ class LocationBriefSerializer(InvenTree.serializers.InvenTreeModelSerializer):
|
||||
class StockItemSerializerBrief(InvenTree.serializers.InvenTreeModelSerializer):
|
||||
"""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)
|
||||
|
||||
quantity = InvenTreeDecimalField()
|
||||
@ -60,7 +59,6 @@ class StockItemSerializerBrief(InvenTree.serializers.InvenTreeModelSerializer):
|
||||
'part_name',
|
||||
'pk',
|
||||
'location',
|
||||
'location_name',
|
||||
'quantity',
|
||||
'serial',
|
||||
'supplier_part',
|
||||
|
@ -731,6 +731,7 @@ function loadBuildOrderAllocationTable(table, options={}) {
|
||||
options.params['part_detail'] = true;
|
||||
options.params['build_detail'] = true;
|
||||
options.params['location_detail'] = true;
|
||||
options.params['stock_detail'] = true;
|
||||
|
||||
var filters = loadTableFilters('buildorderallocation');
|
||||
|
||||
@ -1718,9 +1719,10 @@ function loadBuildOutputAllocationTable(buildInfo, output, options={}) {
|
||||
field: 'location',
|
||||
title: '{% trans "Location" %}',
|
||||
formatter: function(value, row) {
|
||||
if (row.stock_item_detail.location) {
|
||||
var text = row.stock_item_detail.location_name;
|
||||
var url = `/stock/location/${row.stock_item_detail.location}/`;
|
||||
|
||||
if (row.location && row.location_detail) {
|
||||
var text = row.location_detail.name;
|
||||
var url = `/stock/location/${row.location}/`;
|
||||
|
||||
return renderLink(text, url);
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user