2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 12:35:46 +00:00

Auto-calculate quantity based on available stock items

This commit is contained in:
Oliver Walters
2022-12-21 23:46:13 +11:00
parent a3b52dad80
commit f6f6dd01e1
2 changed files with 18 additions and 2 deletions

View File

@ -470,7 +470,11 @@
loadPartStocktakeTable({{ part.pk }}); loadPartStocktakeTable({{ part.pk }});
$('#btn-stocktake').click(function() { $('#btn-stocktake').click(function() {
performStocktake({{ part.pk }}); performStocktake({{ part.pk }}, {
onSuccess: function() {
$('#part-stocktake-table').bootstrapTable('refresh');
}
});
}); });
}); });

View File

@ -723,6 +723,8 @@ function partDetail(part, options={}) {
*/ */
function performStocktake(partId, options={}) { function performStocktake(partId, options={}) {
var part_quantity = 0;
// Helper function for formatting a StockItem row // Helper function for formatting a StockItem row
function buildStockItemRow(item) { function buildStockItemRow(item) {
@ -737,10 +739,14 @@ function performStocktake(partId, options={}) {
// Quantity detail // Quantity detail
var quantity = item.quantity; var quantity = item.quantity;
part_quantity += item.quantity;
if (item.serial && item.quantity == 1) { if (item.serial && item.quantity == 1) {
quantity = `{% trans "Serial" %}: ${item.serial}` quantity = `{% trans "Serial" %}: ${item.serial}`
} }
quantity += stockStatusDisplay(item.status, {classes: 'float-right'});
// Last update // Last update
var updated = item.updated || item.stocktake_date; var updated = item.updated || item.stocktake_date;
@ -801,8 +807,13 @@ function performStocktake(partId, options={}) {
value: partId, value: partId,
hidden: true, hidden: true,
}, },
quantity: {}, quantity: {
value: part_quantity,
},
note: {}, note: {},
},
onSuccess: function(response) {
handleFormSuccess(response, options);
} }
}); });
} }
@ -836,6 +847,7 @@ function loadPartStocktakeTable(partId, options={}) {
name: 'partstocktake', name: 'partstocktake',
original: options.params, original: options.params,
showColumns: true, showColumns: true,
sortable: true,
formatNoMatches: function() { formatNoMatches: function() {
return '{% trans "No stocktake information available" %}'; return '{% trans "No stocktake information available" %}';
}, },