diff --git a/InvenTree/part/templates/part/stock.html b/InvenTree/part/templates/part/stock.html index 5bece01f2e..d41a735989 100644 --- a/InvenTree/part/templates/part/stock.html +++ b/InvenTree/part/templates/part/stock.html @@ -45,50 +45,11 @@ }); }); - $("#stock-table").bootstrapTable({ - sortable: true, - search: true, - pagination: true, - queryParams: function(p) { - return { - part: {{ part.id }}, - in_stock: true, - } + loadStockTable($("#stock-table"), { + params: { + part: {{ part.id }}, }, - columns: [ - { - field: 'pk', - title: 'ID', - visible: false, - }, - { - checkbox: true, - }, - { - field: 'location', - title: 'Location', - sortable: true, - formatter: function(value, row, index, field){ - return renderLink(value.pathstring, value.url); - } - }, - { - field: 'quantity', - title: 'Stock', - searchable: false, - sortable: true, - formatter: function(value, row, index, field) { - var text = renderLink(value, row.url) - text = text + "" + row.status + ""; - return text; - } - }, - { - field: 'notes', - title: 'Notes', - }, - ], - url: "{% url 'api-stock-list' %}" + url: "{% url 'api-stock-list' %}", }); function selectedStock() { diff --git a/InvenTree/static/script/inventree/stock.js b/InvenTree/static/script/inventree/stock.js index 4f008aec0c..d08b705023 100644 --- a/InvenTree/static/script/inventree/stock.js +++ b/InvenTree/static/script/inventree/stock.js @@ -277,4 +277,64 @@ function deleteStockItems(items, options) { modal: modal, title: 'Delete ' + items.length + ' stock items' }); -} \ No newline at end of file +} + + +function loadStockTable(modal, options) { + modal.bootstrapTable({ + sortable: true, + search: true, + method: 'get', + pagination: true, + rememberOrder: true, + queryParams: options.params, + columns: [ + { + checkbox: true, + title: 'Select', + searchable: false, + }, + { + field: 'pk', + title: 'ID', + visible: false, + }, + { + field: 'part.name', + title: 'Part', + sortable: true, + formatter: function(value, row, index, field) { + return renderLink(value, row.part.url); + } + }, + { + field: 'location', + title: 'Location', + sortable: true, + formatter: function(value, row, index, field) { + if (row.location) { + return renderLink(row.location.pathstring, row.location.url); + } + else { + return ''; + } + } + }, + { + field: 'quantity', + title: 'Quantity', + sortable: true, + formatter: function(value, row, index, field) { + var text = renderLink(value, row.url); + text = text + "" + row.status + ""; + return text; + } + }, + { + field: 'notes', + title: 'Notes', + } + ], + url: options.url, + }); +}; \ No newline at end of file diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 5a232ec74f..dc68a198b5 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -9,6 +9,7 @@
{{ location.description }}
{% else %}All stock items
{% endif %}