mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
StockItem: filtering improvements
- Optional 'cacade' param - Filter by null parent
This commit is contained in:
parent
fb94949538
commit
d4da6211be
@ -42,6 +42,10 @@ function loadStockTable(table, options) {
|
||||
|
||||
var params = options.params || {};
|
||||
|
||||
// Enforce 'cascade' option
|
||||
// TODO - Make this user-configurable?
|
||||
params.cascade = true;
|
||||
|
||||
console.log('load stock table');
|
||||
|
||||
table.inventreeTable({
|
||||
|
@ -396,13 +396,24 @@ class StockList(generics.ListCreateAPIView):
|
||||
# Does the client wish to filter by stock location?
|
||||
loc_id = self.request.query_params.get('location', None)
|
||||
|
||||
if loc_id:
|
||||
try:
|
||||
location = StockLocation.objects.get(pk=loc_id)
|
||||
stock_list = stock_list.filter(location__in=location.getUniqueChildren())
|
||||
cascade = str2bool(self.request.query_params.get('cascade', False))
|
||||
|
||||
except (ValueError, StockLocation.DoesNotExist):
|
||||
pass
|
||||
if loc_id is not None:
|
||||
|
||||
# Filter by 'null' location (i.e. top-level items)
|
||||
if isNull(loc_id):
|
||||
stock_list = stock_list.filter(location=None)
|
||||
else:
|
||||
try:
|
||||
# If '?cascade=true' then include items which exist in sub-locations
|
||||
if cascade:
|
||||
location = StockLocation.objects.get(pk=loc_id)
|
||||
stock_list = stock_list.filter(location__in=location.getUniqueChildren())
|
||||
else:
|
||||
stock_list = stock_list.filter(location=loc_id)
|
||||
|
||||
except (ValueError, StockLocation.DoesNotExist):
|
||||
pass
|
||||
|
||||
# Does the client wish to filter by part category?
|
||||
cat_id = self.request.query_params.get('category', None)
|
||||
|
Loading…
Reference in New Issue
Block a user