2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 03:00:54 +00:00

Child items table (#5114)

* Template cleanup

- Remove "buttons" attribute (outdated)

* Fix filters for "child stock items" table

* Fix 'ancestor' stock filter
This commit is contained in:
Oliver
2023-06-28 15:22:23 +10:00
committed by GitHub
parent 53e120cdb3
commit a78b26f93a
9 changed files with 29 additions and 47 deletions

View File

@ -552,6 +552,19 @@ class StockFilter(rest_filters.FilterSet):
else:
return queryset.filter(purchase_price=None)
ancestor = rest_filters.ModelChoiceFilter(
label='Ancestor',
queryset=StockItem.objects.all(),
method='filter_ancestor'
)
def filter_ancestor(self, queryset, name, ancestor):
"""Filter based on ancestor stock item"""
return queryset.filter(
parent__in=ancestor.get_descendants(include_self=True)
)
# Update date filters
updated_before = rest_filters.DateFilter(label='Updated before', field_name='updated', lookup_expr='lte')
updated_after = rest_filters.DateFilter(label='Updated after', field_name='updated', lookup_expr='gte')
@ -929,19 +942,6 @@ class StockList(APIDownloadMixin, ListCreateDestroyAPIView):
except (ValueError, Part.DoesNotExist):
raise ValidationError({"part": "Invalid Part ID specified"})
# Does the client wish to filter by the 'ancestor'?
anc_id = params.get('ancestor', None)
if anc_id:
try:
ancestor = StockItem.objects.get(pk=anc_id)
# Only allow items which are descendants of the specified StockItem
queryset = queryset.filter(id__in=[item.pk for item in ancestor.children.all()])
except (ValueError, Part.DoesNotExist):
raise ValidationError({"ancestor": "Invalid ancestor ID specified"})
# Does the client wish to filter by stock location?
loc_id = params.get('location', None)

View File

@ -65,6 +65,7 @@
</div>
<div class='panel-content'>
{% if item.child_count > 0 %}
{% include "filter_list.html" with id="stock-childs" %}
{% include "stock_table.html" with prefix="childs-" %}
{% else %}
<div class='alert alert-block alert-info'>
@ -300,14 +301,11 @@
{% if item.child_count > 0 %}
loadStockTable($("#childs-stock-table"), {
params: {
location_detail: true,
part_detail: false,
ancestor: {{ item.id }},
},
name: 'item-childs',
buttons: [
'#stock-options',
],
filterTarget: '#filter-list-stock-childs',
filterKey: 'stock',
});
{% endif %}

View File

@ -403,9 +403,6 @@
onPanelLoad('stock', function() {
loadStockTable($("#stock-table"), {
buttons: [
'#stock-options',
],
params: {
{% if location %}
location: {{ location.pk }},