diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index 525b6767d6..c2220776d7 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -463,11 +463,9 @@ $("#print-label").click(function() { {% if roles.stock.change %} $("#stock-duplicate").click(function() { - createNewStockItem({ + // Duplicate a stock item + duplicateStockItem({{ item.pk }}, { follow: true, - data: { - copy: {{ item.id }}, - } }); }); diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index 7cf839496b..e968da3769 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -106,6 +106,8 @@ function createStockLocation(options={}) { function stockItemFields(options={}) { var fields = { part: { + // Hide the part field unless we are "creating" a new stock item + hidden: !options.create, onSelect: function(data, field, opts) { // Callback when a new "part" is selected @@ -205,6 +207,29 @@ function stockItemGroups(options={}) { } +/* + * Launch a modal form to duplicate a given StockItem + */ +function duplicateStockItem(pk, options) { + + // First, we need the StockItem informatino + inventreeGet(`/api/stock/${pk}/`, {}, { + success: function(data) { + + options.create = true; + + options.data = data; + options.method = 'POST'; + options.fields = stockItemFields(options); + options.groups = stockItemGroups(options); + options.title = '{% trans "Duplicate Stock Item" %}'; + + constructForm('{% url "api-stock-list" %}', options); + } + }); +} + + /* * Launch a modal form to edit a given StockItem */ @@ -212,9 +237,6 @@ function editStockItem(pk, options={}) { var url = `/api/stock/${pk}/`; - // Prevent editing of the "part" - fields.part.hidden = true; - options.create = false; options.fields = stockItemFields(options);