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