mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 04:55:44 +00:00
Add ability to quickly duplicate build orders (#3565)
* Adds ability to easily duplicate an existing build order * Refactor purchase order editing code
This commit is contained in:
@ -23,6 +23,7 @@
|
||||
cancelBuildOrder,
|
||||
completeBuildOrder,
|
||||
createBuildOutput,
|
||||
duplicateBuildOrder,
|
||||
editBuildOrder,
|
||||
loadAllocationTable,
|
||||
loadBuildOrderAllocationTable,
|
||||
@ -75,7 +76,9 @@ function buildFormFields() {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Edit an existing BuildOrder via the API
|
||||
*/
|
||||
function editBuildOrder(pk) {
|
||||
|
||||
var fields = buildFormFields();
|
||||
@ -87,6 +90,10 @@ function editBuildOrder(pk) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Create a new build order via an API form
|
||||
*/
|
||||
function newBuildOrder(options={}) {
|
||||
/* Launch modal form to create a new BuildOrder.
|
||||
*/
|
||||
@ -113,8 +120,13 @@ function newBuildOrder(options={}) {
|
||||
fields.sales_order.value = options.sales_order;
|
||||
}
|
||||
|
||||
if (options.data) {
|
||||
delete options.data.pk;
|
||||
}
|
||||
|
||||
constructForm(`/api/build/`, {
|
||||
fields: fields,
|
||||
data: options.data,
|
||||
follow: true,
|
||||
method: 'POST',
|
||||
title: '{% trans "Create Build Order" %}',
|
||||
@ -123,6 +135,26 @@ function newBuildOrder(options={}) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Duplicate an existing build order.
|
||||
*/
|
||||
function duplicateBuildOrder(build_id, options={}) {
|
||||
|
||||
inventreeGet(`/api/build/${build_id}/`, {}, {
|
||||
success: function(data) {
|
||||
// Clear out data we do not want to be duplicated
|
||||
delete data['pk'];
|
||||
delete data['issued_by'];
|
||||
delete data['reference'];
|
||||
|
||||
options.data = data;
|
||||
newBuildOrder(options);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Construct a form to cancel a build order */
|
||||
function cancelBuildOrder(build_id, options={}) {
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
createPurchaseOrderLineItem,
|
||||
createSalesOrder,
|
||||
createSalesOrderShipment,
|
||||
editPurchaseOrder,
|
||||
editPurchaseOrderLineItem,
|
||||
exportOrder,
|
||||
issuePurchaseOrder,
|
||||
@ -493,41 +494,79 @@ function createSalesOrder(options={}) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Construct a set of fields for a purchase order form
|
||||
*/
|
||||
function purchaseOrderFields(options={}) {
|
||||
|
||||
var fields = {
|
||||
reference: {
|
||||
icon: 'fa-hashtag',
|
||||
},
|
||||
supplier: {
|
||||
icon: 'fa-building',
|
||||
secondary: {
|
||||
title: '{% trans "Add Supplier" %}',
|
||||
fields: function() {
|
||||
var fields = companyFormFields();
|
||||
|
||||
fields.is_supplier.value = true;
|
||||
|
||||
return fields;
|
||||
}
|
||||
}
|
||||
},
|
||||
description: {},
|
||||
supplier_reference: {},
|
||||
target_date: {
|
||||
icon: 'fa-calendar-alt',
|
||||
},
|
||||
link: {
|
||||
icon: 'fa-link',
|
||||
},
|
||||
responsible: {
|
||||
icon: 'fa-user',
|
||||
},
|
||||
};
|
||||
|
||||
if (options.supplier) {
|
||||
fields.supplier.value = options.supplier;
|
||||
}
|
||||
|
||||
if (options.hide_supplier) {
|
||||
fields.supplier.hidden = true;
|
||||
}
|
||||
|
||||
return fields;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Edit an existing PurchaseOrder
|
||||
*/
|
||||
function editPurchaseOrder(pk, options={}) {
|
||||
|
||||
var fields = purchaseOrderFields(options);
|
||||
|
||||
constructForm(`/api/order/po/${pk}/`, {
|
||||
fields: fields,
|
||||
title: '{% trans "Edit Purchase Order" %}',
|
||||
onSuccess: function(response) {
|
||||
handleFormSuccess(response, options);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Create a new PurchaseOrder
|
||||
function createPurchaseOrder(options={}) {
|
||||
|
||||
var fields = purchaseOrderFields(options);
|
||||
|
||||
constructForm('{% url "api-po-list" %}', {
|
||||
method: 'POST',
|
||||
fields: {
|
||||
reference: {
|
||||
icon: 'fa-hashtag',
|
||||
},
|
||||
supplier: {
|
||||
icon: 'fa-building',
|
||||
value: options.supplier,
|
||||
secondary: {
|
||||
title: '{% trans "Add Supplier" %}',
|
||||
fields: function() {
|
||||
var fields = companyFormFields();
|
||||
|
||||
fields.is_supplier.value = true;
|
||||
|
||||
return fields;
|
||||
}
|
||||
}
|
||||
},
|
||||
description: {},
|
||||
supplier_reference: {},
|
||||
target_date: {
|
||||
icon: 'fa-calendar-alt',
|
||||
},
|
||||
link: {
|
||||
icon: 'fa-link',
|
||||
},
|
||||
responsible: {
|
||||
icon: 'fa-user',
|
||||
}
|
||||
},
|
||||
fields: fields,
|
||||
onSuccess: function(data) {
|
||||
|
||||
if (options.onSuccess) {
|
||||
|
Reference in New Issue
Block a user