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 || {};
|
var params = options.params || {};
|
||||||
|
|
||||||
|
// Enforce 'cascade' option
|
||||||
|
// TODO - Make this user-configurable?
|
||||||
|
params.cascade = true;
|
||||||
|
|
||||||
console.log('load stock table');
|
console.log('load stock table');
|
||||||
|
|
||||||
table.inventreeTable({
|
table.inventreeTable({
|
||||||
|
@ -396,10 +396,21 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
# Does the client wish to filter by stock location?
|
# Does the client wish to filter by stock location?
|
||||||
loc_id = self.request.query_params.get('location', None)
|
loc_id = self.request.query_params.get('location', None)
|
||||||
|
|
||||||
if loc_id:
|
cascade = str2bool(self.request.query_params.get('cascade', False))
|
||||||
|
|
||||||
|
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:
|
try:
|
||||||
|
# If '?cascade=true' then include items which exist in sub-locations
|
||||||
|
if cascade:
|
||||||
location = StockLocation.objects.get(pk=loc_id)
|
location = StockLocation.objects.get(pk=loc_id)
|
||||||
stock_list = stock_list.filter(location__in=location.getUniqueChildren())
|
stock_list = stock_list.filter(location__in=location.getUniqueChildren())
|
||||||
|
else:
|
||||||
|
stock_list = stock_list.filter(location=loc_id)
|
||||||
|
|
||||||
except (ValueError, StockLocation.DoesNotExist):
|
except (ValueError, StockLocation.DoesNotExist):
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user