From f6f6dd01e161d385fae46d491289a8881949e7cf Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 21 Dec 2022 23:46:13 +1100 Subject: [PATCH] Auto-calculate quantity based on available stock items --- InvenTree/part/templates/part/detail.html | 6 +++++- InvenTree/templates/js/translated/part.js | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index fa3e35235e..ed94a3322d 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -470,7 +470,11 @@ loadPartStocktakeTable({{ part.pk }}); $('#btn-stocktake').click(function() { - performStocktake({{ part.pk }}); + performStocktake({{ part.pk }}, { + onSuccess: function() { + $('#part-stocktake-table').bootstrapTable('refresh'); + } + }); }); }); diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index eb414f3d1e..e51e0a4149 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -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" %}'; },