2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 19:46:46 +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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 47 deletions

View File

@ -306,9 +306,6 @@ onPanelLoad('completed', function() {
build: {{ build.id }}, build: {{ build.id }},
is_building: false, is_building: false,
}, },
buttons: [
'#stock-options',
],
}); });
}); });

View File

@ -319,9 +319,6 @@
supplier_part_detail: true, supplier_part_detail: true,
location_detail: true, location_detail: true,
}, },
buttons: [
'#stock-options',
],
filterKey: "companystock", filterKey: "companystock",
}); });
}); });

View File

@ -322,7 +322,6 @@ loadStockTable($("#stock-table"), {
location_detail: true, location_detail: true,
part_detail: false, part_detail: false,
}, },
buttons: ['#stock-options'],
}); });
$("#item-create").click(function() { $("#item-create").click(function() {

View File

@ -150,9 +150,6 @@
supplier_part_detail: true, supplier_part_detail: true,
location_detail: true, location_detail: true,
}, },
buttons: [
'#stock-options',
],
filterkey: "postock" filterkey: "postock"
}); });

View File

@ -769,9 +769,6 @@
part_detail: true, part_detail: true,
supplier_part_detail: true, supplier_part_detail: true,
}, },
buttons: [
'#stock-options',
],
}); });
$('#item-create').click(function () { $('#item-create').click(function () {

View File

@ -552,6 +552,19 @@ class StockFilter(rest_filters.FilterSet):
else: else:
return queryset.filter(purchase_price=None) 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 # Update date filters
updated_before = rest_filters.DateFilter(label='Updated before', field_name='updated', lookup_expr='lte') 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') 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): except (ValueError, Part.DoesNotExist):
raise ValidationError({"part": "Invalid Part ID specified"}) 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? # Does the client wish to filter by stock location?
loc_id = params.get('location', None) loc_id = params.get('location', None)

View File

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

View File

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

View File

@ -1834,6 +1834,8 @@ function makeStockActions(table) {
*/ */
function loadStockTable(table, options) { function loadStockTable(table, options) {
options.params = options.params || {};
// List of user-params which override the default filters // List of user-params which override the default filters
options.params['location_detail'] = true; options.params['location_detail'] = true;
options.params['part_detail'] = true; options.params['part_detail'] = true;
@ -1841,8 +1843,6 @@ function loadStockTable(table, options) {
// Determine if installed items are displayed in the table // Determine if installed items are displayed in the table
let show_installed_items = global_settings.STOCK_SHOW_INSTALLED_ITEMS; let show_installed_items = global_settings.STOCK_SHOW_INSTALLED_ITEMS;
var params = options.params || {};
let filters = {}; let filters = {};
if (!options.disableFilters) { if (!options.disableFilters) {
@ -1850,7 +1850,7 @@ function loadStockTable(table, options) {
const filterTarget = options.filterTarget || '#filter-list-stock'; const filterTarget = options.filterTarget || '#filter-list-stock';
const filterKey = options.filterKey || options.name || 'stock'; const filterKey = options.filterKey || options.name || 'stock';
filters = loadTableFilters(filterKey, params); filters = loadTableFilters(filterKey, options.params);
setupFilterList(filterKey, table, filterTarget, { setupFilterList(filterKey, table, filterTarget, {
download: true, download: true,
@ -1886,7 +1886,7 @@ function loadStockTable(table, options) {
}); });
} }
filters = Object.assign(filters, params); filters = Object.assign(filters, options.params);
var col = null; var col = null;
@ -1909,8 +1909,8 @@ function loadStockTable(table, options) {
field: 'part', field: 'part',
title: '{% trans "Part" %}', title: '{% trans "Part" %}',
sortName: 'part__name', sortName: 'part__name',
visible: params['part_detail'], visible: options.params['part_detail'],
switchable: params['part_detail'], switchable: options.params['part_detail'],
formatter: function(value, row) { formatter: function(value, row) {
let html = ''; let html = '';
@ -1948,8 +1948,8 @@ function loadStockTable(table, options) {
field: 'IPN', field: 'IPN',
title: '{% trans "IPN" %}', title: '{% trans "IPN" %}',
sortName: 'part__IPN', sortName: 'part__IPN',
visible: params['part_detail'], visible: options.params['part_detail'],
switchable: params['part_detail'], switchable: options.params['part_detail'],
formatter: function(value, row) { formatter: function(value, row) {
var ipn = row.part_detail.IPN; var ipn = row.part_detail.IPN;
if (ipn) { if (ipn) {
@ -1969,8 +1969,8 @@ function loadStockTable(table, options) {
columns.push({ columns.push({
field: 'part_detail.description', field: 'part_detail.description',
title: '{% trans "Description" %}', title: '{% trans "Description" %}',
visible: params['part_detail'], visible: options.params['part_detail'],
switchable: params['part_detail'], switchable: options.params['part_detail'],
formatter: function(value, row) { formatter: function(value, row) {
var description = row.part_detail.description; var description = row.part_detail.description;
return withTitle(shortenString(description), description); return withTitle(shortenString(description), description);
@ -2168,8 +2168,8 @@ function loadStockTable(table, options) {
field: 'supplier_part', field: 'supplier_part',
title: '{% trans "Supplier Part" %}', title: '{% trans "Supplier Part" %}',
visible: params['supplier_part_detail'] || false, visible: options.params['supplier_part_detail'] || false,
switchable: params['supplier_part_detail'] || false, switchable: options.params['supplier_part_detail'] || false,
formatter: function(value, row) { formatter: function(value, row) {
if (!value) { if (!value) {
return '-'; return '-';
@ -2358,7 +2358,7 @@ function loadStockTable(table, options) {
queryParams: filters, queryParams: filters,
sidePagination: 'server', sidePagination: 'server',
name: 'stock', name: 'stock',
original: params, original: options.params,
showColumns: true, showColumns: true,
showFooter: true, showFooter: true,
columns: columns, columns: columns,