From b99a9306ce70e6db2c8d65c1f5218c8b8cab6ab5 Mon Sep 17 00:00:00 2001
From: Maksim Stojkovic <18454392+maksimstojkovic@users.noreply.github.com>
Date: Fri, 20 May 2022 20:37:23 +1000
Subject: [PATCH 5/9] Added onSuccess support to completeShipment
---
InvenTree/templates/js/translated/order.js | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js
index e6a18db96b..a6d8cbdc0d 100644
--- a/InvenTree/templates/js/translated/order.js
+++ b/InvenTree/templates/js/translated/order.js
@@ -126,7 +126,7 @@ function completeShipment(shipment_id, options={}) {
constructForm(`/api/order/so/shipment/${shipment_id}/ship/`, {
method: 'POST',
- title: '{% trans "Complete Shipment" %}',
+ title: `{% trans "Complete Shipment" %} ${shipment.reference}`,
fields: {
tracking_number: {},
},
@@ -138,6 +138,10 @@ function completeShipment(shipment_id, options={}) {
$('#so-lines-table').bootstrapTable('refresh');
$('#pending-shipments-table').bootstrapTable('refresh');
$('#completed-shipments-table').bootstrapTable('refresh');
+
+ if (options.onSuccess instanceof Function) {
+ options.onSuccess(data);
+ }
},
reload: !!options.reload
});
@@ -147,7 +151,7 @@ function completeShipment(shipment_id, options={}) {
/*
* Launches a modal form to mark a PurchaseOrder as "complete"
-*/
+ */
function completePurchaseOrder(order_id, options={}) {
constructForm(
From f1ca9d7aa8f95f089edd9d939887dd443d636d2e Mon Sep 17 00:00:00 2001
From: Maksim Stojkovic <18454392+maksimstojkovic@users.noreply.github.com>
Date: Fri, 20 May 2022 22:22:49 +1000
Subject: [PATCH 6/9] Added div for extra secondary modal buttons
---
InvenTree/templates/js/translated/modals.js | 3 +++
1 file changed, 3 insertions(+)
diff --git a/InvenTree/templates/js/translated/modals.js b/InvenTree/templates/js/translated/modals.js
index 023fcd26ce..cc1212494d 100644
--- a/InvenTree/templates/js/translated/modals.js
+++ b/InvenTree/templates/js/translated/modals.js
@@ -75,6 +75,9 @@ function createNewModal(options={}) {
+
From 3eb489801951e6739d6e41cf2fccf16b21dcf136 Mon Sep 17 00:00:00 2001
From: Maksim Stojkovic <18454392+maksimstojkovic@users.noreply.github.com>
Date: Sat, 21 May 2022 00:52:45 +1000
Subject: [PATCH 7/9] Added support for secondary buttons on modals Secondary
buttons can be added to modal footers beside Close and Submit Buttons can be
linked to callback functions Callback functions can access options arguments
passed to constructForm
---
InvenTree/templates/js/translated/forms.js | 30 ++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/InvenTree/templates/js/translated/forms.js b/InvenTree/templates/js/translated/forms.js
index d45a2de78c..9e1a7d154d 100644
--- a/InvenTree/templates/js/translated/forms.js
+++ b/InvenTree/templates/js/translated/forms.js
@@ -561,6 +561,11 @@ function constructFormBody(fields, options) {
insertPersistButton(options);
}
+ // Insert secondary buttons (if required)
+ if (options.buttons) {
+ insertSecondaryButtons(options);
+ }
+
// Display the modal
$(modal).modal('show');
@@ -650,6 +655,31 @@ function insertPersistButton(options) {
$(options.modal).find('#modal-footer-buttons').append(html);
}
+/*
+ * Add secondary buttons to the left of the close and submit buttons
+ * with callback functions
+ */
+function insertSecondaryButtons(options) {
+ for (var idx = 0; idx < options.buttons.length; idx++) {
+
+ var html = `
+
+ `;
+
+ $(options.modal).find('#modal-footer-secondary-buttons').append(html);
+
+ if (options.buttons[idx].onClick instanceof Function) {
+ // Copy callback reference to prevent errors if `idx` changes value before execution
+ var onclick_callback = options.buttons[idx].onClick;
+
+ $(options.modal).find(`#modal-form-${options.buttons[idx].name}`).click(function() {
+ onclick_callback(options);
+ });
+ }
+ }
+}
/*
* Extract all specified form values as a single object
From c38862b28ce4ea9728332f9f521c60297562a62e Mon Sep 17 00:00:00 2001
From: Maksim Stojkovic <18454392+maksimstojkovic@users.noreply.github.com>
Date: Sat, 21 May 2022 01:05:54 +1000
Subject: [PATCH 8/9] Added page action to process pending shipments
---
.../templates/order/sales_order_base.html | 2 +-
InvenTree/templates/js/translated/order.js | 98 ++++++++++++++++++-
2 files changed, 98 insertions(+), 2 deletions(-)
diff --git a/InvenTree/order/templates/order/sales_order_base.html b/InvenTree/order/templates/order/sales_order_base.html
index 83ba6d9614..af923ab097 100644
--- a/InvenTree/order/templates/order/sales_order_base.html
+++ b/InvenTree/order/templates/order/sales_order_base.html
@@ -226,7 +226,7 @@ $("#edit-order").click(function() {
$("#complete-order-shipments").click(function() {
- completeShipments(
+ completePendingShipments(
{{ order.pk }},
{
reload: true,
diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js
index a6d8cbdc0d..b9b6da3b36 100644
--- a/InvenTree/templates/js/translated/order.js
+++ b/InvenTree/templates/js/translated/order.js
@@ -133,6 +133,7 @@ function completeShipment(shipment_id, options={}) {
preFormContent: html,
confirm: true,
confirmMessage: '{% trans "Confirm Shipment" %}',
+ buttons: options.buttons,
onSuccess: function(data) {
// Reload tables
$('#so-lines-table').bootstrapTable('refresh');
@@ -143,12 +144,107 @@ function completeShipment(shipment_id, options={}) {
options.onSuccess(data);
}
},
- reload: !!options.reload
+ reload: options.reload
});
}
});
}
+/*
+ * Launches a modal to mark all allocated pending shipments as complete
+ */
+function completePendingShipments(order_id, options={}) {
+ var pending_shipments = null;
+
+ // Request the list of stock items which will be shipped
+ inventreeGet(`/api/order/so/shipment/.*`,
+ {
+ order: order_id,
+ shipped: false
+ },
+ {
+ async: false,
+ success: function(shipments) {
+ pending_shipments = shipments;
+ }
+ }
+ );
+
+ var allocated_shipments = [];
+
+ for (var idx = 0; idx < pending_shipments.length; idx++) {
+ if (pending_shipments[idx].allocations.length > 0) {
+ allocated_shipments.push(pending_shipments[idx]);
+ }
+ }
+
+ if (allocated_shipments.length > 0) {
+ completePendingShipmentsHelper(allocated_shipments, 0, options);
+
+ } else {
+ html = `
+
+ `;
+
+ if (!pending_shipments.length) {
+ html += `
+ {% trans "No pending shipments found" %}
+ `;
+ } else {
+ html += `
+ {% trans "No stock items have been allocated to pending shipments" %}
+ `;
+ }
+
+ html += `
+