diff --git a/InvenTree/build/templates/build/build_base.html b/InvenTree/build/templates/build/build_base.html
index 8c051d7f67..2f3e339b7d 100644
--- a/InvenTree/build/templates/build/build_base.html
+++ b/InvenTree/build/templates/build/build_base.html
@@ -55,6 +55,9 @@ src="{% static 'img/blank_image.png' %}"
{% if build.is_active %}
{% trans "Cancel Build" %}
{% endif %}
+ {% if roles.build.add %}
+ {% trans "Duplicate Build" %}
+ {% endif %}
{% if build.status == BuildStatus.CANCELLED and roles.build.delete %}
{% trans "Delete Build" %}
{% endif %}
@@ -209,6 +212,7 @@ src="{% static 'img/blank_image.png' %}"
{% block js_ready %}
+ {% if roles.build.change %}
$("#build-edit").click(function () {
editBuildOrder({{ build.pk }});
});
@@ -230,6 +234,13 @@ src="{% static 'img/blank_image.png' %}"
completed: {% if build.remaining == 0 %}true{% else %}false{% endif %},
});
});
+ {% endif %}
+
+ {% if roles.build.add %}
+ $('#build-duplicate').click(function() {
+ duplicateBuildOrder({{ build.pk }});
+ });
+ {% endif %}
{% if report_enabled %}
$('#print-build-report').click(function() {
diff --git a/InvenTree/order/templates/order/order_base.html b/InvenTree/order/templates/order/order_base.html
index 2d16796bc3..000d4c7751 100644
--- a/InvenTree/order/templates/order/order_base.html
+++ b/InvenTree/order/templates/order/order_base.html
@@ -219,28 +219,10 @@ $('#print-order-report').click(function() {
$("#edit-order").click(function() {
- constructForm('{% url "api-po-detail" order.pk %}', {
- fields: {
- reference: {
- icon: 'fa-hashtag',
- },
- {% if order.lines.count == 0 and order.status == PurchaseOrderStatus.PENDING %}
- supplier: {
- },
- {% endif %}
- supplier_reference: {},
- description: {},
- target_date: {
- icon: 'fa-calendar-alt',
- },
- link: {
- icon: 'fa-link',
- },
- responsible: {
- icon: 'fa-user',
- },
- },
- title: '{% trans "Edit Purchase Order" %}',
+ editPurchaseOrder({{ order.pk }}, {
+ {% if order.lines.count > 0 or order.status != PurchaseOrderStatus.PENDING %}
+ hide_supplier: true,
+ {% endif %}
reload: true,
});
});
diff --git a/InvenTree/templates/js/translated/build.js b/InvenTree/templates/js/translated/build.js
index 223427e68e..7b42e3216d 100644
--- a/InvenTree/templates/js/translated/build.js
+++ b/InvenTree/templates/js/translated/build.js
@@ -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={}) {
diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js
index 221c0c1d19..fd9421a6e8 100644
--- a/InvenTree/templates/js/translated/order.js
+++ b/InvenTree/templates/js/translated/order.js
@@ -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) {