2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 04:25:42 +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:
Oliver
2022-08-19 17:16:38 +10:00
committed by GitHub
parent 89d5df4f1e
commit b886e54709
5 changed files with 24 additions and 11 deletions

View File

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

View File

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

View File

@ -455,7 +455,9 @@ function loadUntrackedStockTable() {
);
}
loadUntrackedStockTable();
onPanelLoad('allocate', function() {
loadUntrackedStockTable();
});
{% endif %}