mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Stock item duplication now works with the API forms
This commit is contained in:
parent
aaf27d4098
commit
ad4c4f2a6d
@ -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 }},
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user