mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Filtering for Build and StockItem
This commit is contained in:
parent
9cf372f633
commit
4ee0004c97
@ -104,6 +104,21 @@ class BuildList(generics.ListCreateAPIView):
|
|||||||
|
|
||||||
params = self.request.query_params
|
params = self.request.query_params
|
||||||
|
|
||||||
|
# exclude parent tree
|
||||||
|
exclude_tree = params.get('exclude_tree', None)
|
||||||
|
|
||||||
|
if exclude_tree is not None:
|
||||||
|
|
||||||
|
try:
|
||||||
|
build = Build.objects.get(pk=exclude_tree)
|
||||||
|
|
||||||
|
queryset = queryset.exclude(
|
||||||
|
pk__in=[bld.pk for bld in build.get_descendants(include_self=True)]
|
||||||
|
)
|
||||||
|
|
||||||
|
except (ValueError, Build.DoesNotExist):
|
||||||
|
pass
|
||||||
|
|
||||||
# Filter by "parent"
|
# Filter by "parent"
|
||||||
parent = params.get('parent', None)
|
parent = params.get('parent', None)
|
||||||
|
|
||||||
|
@ -96,6 +96,14 @@ class Build(MPTTModel):
|
|||||||
def get_api_url():
|
def get_api_url():
|
||||||
return reverse('api-build-list')
|
return reverse('api-build-list')
|
||||||
|
|
||||||
|
def api_instance_filters(self):
|
||||||
|
|
||||||
|
return {
|
||||||
|
'parent': {
|
||||||
|
'exclude_tree': self.pk,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -733,6 +733,20 @@ class StockList(generics.ListCreateAPIView):
|
|||||||
if customer:
|
if customer:
|
||||||
queryset = queryset.filter(customer=customer)
|
queryset = queryset.filter(customer=customer)
|
||||||
|
|
||||||
|
# Exclude stock item tree
|
||||||
|
exclude_tree = params.get('exclude_tree', None)
|
||||||
|
|
||||||
|
if exclude_tree is not None:
|
||||||
|
try:
|
||||||
|
item = StockItem.objects.get(pk=exclude_tree)
|
||||||
|
|
||||||
|
queryset = queryset.exclude(
|
||||||
|
pk__in=[it.pk for it in item.get_descendants(include_self=True)]
|
||||||
|
)
|
||||||
|
|
||||||
|
except (ValueError, StockItem.DoesNotExist):
|
||||||
|
pass
|
||||||
|
|
||||||
# Filter by 'allocated' parts?
|
# Filter by 'allocated' parts?
|
||||||
allocated = params.get('allocated', None)
|
allocated = params.get('allocated', None)
|
||||||
|
|
||||||
|
@ -191,6 +191,17 @@ class StockItem(MPTTModel):
|
|||||||
def get_api_url():
|
def get_api_url():
|
||||||
return reverse('api-stock-list')
|
return reverse('api-stock-list')
|
||||||
|
|
||||||
|
def api_instance_filters(self):
|
||||||
|
"""
|
||||||
|
Custom API instance filters
|
||||||
|
"""
|
||||||
|
|
||||||
|
return {
|
||||||
|
'parent': {
|
||||||
|
'exclude_tree': self.pk,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# A Query filter which will be re-used in multiple places to determine if a StockItem is actually "in stock"
|
# A Query filter which will be re-used in multiple places to determine if a StockItem is actually "in stock"
|
||||||
IN_STOCK_FILTER = Q(
|
IN_STOCK_FILTER = Q(
|
||||||
quantity__gt=0,
|
quantity__gt=0,
|
||||||
|
Loading…
Reference in New Issue
Block a user