2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-20 13:56:30 +00:00

Part table filtering

- Filter by active status
- Filter by 'is_template' status
- Filter by 'has_stock'
- Allow cascading sublocations
- API improvements to allow new features
This commit is contained in:
Oliver Walters
2020-04-11 22:10:15 +10:00
parent d606df16f7
commit 5e706554b1
5 changed files with 48 additions and 14 deletions

View File

@ -215,6 +215,21 @@ class PartList(generics.ListCreateAPIView):
building=Sum('builds__quantity', filter=build_filter),
)
# If we are filtering by 'has_stock' status,
# Check if the 'has_stock' quantity is zero
has_stock = self.request.query_params.get('has_stock', None)
if has_stock is not None:
has_stock = str2bool(has_stock)
if has_stock:
# Filter items which have a non-null 'in_stock' quantity above zero
data = data.exclude(in_stock=None)
data = data.filter(in_stock__gt=0)
else:
# Filter items which a null or zero 'in_stock' quantity
data = data.filter(Q(in_stock__lte=0) | Q(in_stock=None))
# Reduce the number of lookups we need to do for the part categories
categories = {}

View File

@ -659,7 +659,7 @@ class Part(models.Model):
if total:
return total
else:
return 0
return Decimal(0)
@property
def has_bom(self):

View File

@ -99,7 +99,7 @@
<div class='button-toolbar container-fluid' style="float: right;">
<button class='btn btn-default' id='part-export' title='Export Part Data'>Export</button>
<button class='btn btn-success' id='part-create'>New Part</button>
<div class='dropdown' style='float: right;'>
<div class='btn dropdown'>
<button id='part-options' class='btn btn-primary dropdown-toggle' type='button' data-toggle="dropdown">Options<span class='caret'></span></button>
<ul class='dropdown-menu'>
<li><a href='#' id='multi-part-category' title='Set category'>Set Category</a></li>
@ -107,6 +107,9 @@
<li><a href='#' id='multi-part-export' title='Export'>Export Data</a></li>
</ul>
</div>
<div class='filter-list' id='filter-list-parts'>
<!-- Empty div -->
</div>
</div>
</div>