From 239138a1b5db9462948518f0345c82991c838209 Mon Sep 17 00:00:00 2001 From: Maksim Stojkovic <18454392+maksimstojkovic@users.noreply.github.com> Date: Thu, 19 May 2022 18:58:33 +1000 Subject: [PATCH 1/9] Added page actions menu item --- .../order/templates/order/sales_order_base.html | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/InvenTree/order/templates/order/sales_order_base.html b/InvenTree/order/templates/order/sales_order_base.html index 5593918a38..25357c86c2 100644 --- a/InvenTree/order/templates/order/sales_order_base.html +++ b/InvenTree/order/templates/order/sales_order_base.html @@ -57,6 +57,9 @@ src="{% static 'img/blank_image.png' %}" @@ -223,6 +226,16 @@ $("#edit-order").click(function() { }); }); +$("#complete-order-shipments").click(function() { + + completeShipments( + {{ order.pk }}, + { + reload: true, + } + ); +}); + $("#cancel-order").click(function() { cancelSalesOrder( From f2a3b4ab1fc603c3f509b0ff2a8ca37218b183df Mon Sep 17 00:00:00 2001 From: Maksim Stojkovic <18454392+maksimstojkovic@users.noreply.github.com> Date: Fri, 20 May 2022 16:28:34 +1000 Subject: [PATCH 2/9] Changed completeShipment reload to optional --- InvenTree/templates/js/translated/order.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js index 53dead4b60..e6a18db96b 100644 --- a/InvenTree/templates/js/translated/order.js +++ b/InvenTree/templates/js/translated/order.js @@ -69,7 +69,7 @@ function salesOrderShipmentFields(options={}) { /* * Complete a shipment */ -function completeShipment(shipment_id) { +function completeShipment(shipment_id, options={}) { // Request the list of stock items which will be shipped inventreeGet(`/api/order/so/shipment/${shipment_id}/`, {}, { @@ -139,7 +139,7 @@ function completeShipment(shipment_id) { $('#pending-shipments-table').bootstrapTable('refresh'); $('#completed-shipments-table').bootstrapTable('refresh'); }, - reload: true + reload: !!options.reload }); } }); From c6b9585c02152bb15423ee0c5991e5ddae0cc51a Mon Sep 17 00:00:00 2001 From: Maksim Stojkovic <18454392+maksimstojkovic@users.noreply.github.com> Date: Fri, 20 May 2022 18:28:02 +1000 Subject: [PATCH 3/9] Fixed typo --- InvenTree/templates/js/translated/modals.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/templates/js/translated/modals.js b/InvenTree/templates/js/translated/modals.js index 464006ae12..023fcd26ce 100644 --- a/InvenTree/templates/js/translated/modals.js +++ b/InvenTree/templates/js/translated/modals.js @@ -99,7 +99,7 @@ function createNewModal(options={}) { $(modal_name).focus(); if (options.hideCloseButton) { - $(modal_name).find('#modal-form-cancel').hide(); + $(modal_name).find('#modal-form-close').hide(); } if (options.preventSubmit || options.hideSubmitButton) { From af0901d06cc56d865db0ebb01c67d99591888efb Mon Sep 17 00:00:00 2001 From: Maksim Stojkovic <18454392+maksimstojkovic@users.noreply.github.com> Date: Fri, 20 May 2022 19:30:19 +1000 Subject: [PATCH 4/9] Changed complete shipments button to always show --- InvenTree/order/templates/order/sales_order_base.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/InvenTree/order/templates/order/sales_order_base.html b/InvenTree/order/templates/order/sales_order_base.html index 25357c86c2..83ba6d9614 100644 --- a/InvenTree/order/templates/order/sales_order_base.html +++ b/InvenTree/order/templates/order/sales_order_base.html @@ -57,9 +57,7 @@ src="{% static 'img/blank_image.png' %}" 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 += ` +
+ `; + + constructForm(`/api/order/so/shipment/0/ship/`, { + method: 'POST', + title: '{% trans "Complete Shipments" %}', + preFormContent: html, + onSubmit: function(fields, options) { + handleFormSuccess(fields, options); + }, + closeText: 'Close', + hideSubmitButton: true, + }); + } +} + + +/* + * Recursive helper for opening shipment completion modals + */ +function completePendingShipmentsHelper(shipments, shipment_idx, options={}) { + if (shipment_idx < shipments.length) { + completeShipment(shipments[shipment_idx].pk, + { + buttons: [ + { + name: 'skip', + title: `{% trans "Skip" %}`, + onClick: function(form_options) { + if (form_options.modal) { + $(form_options.modal).modal('hide'); + } + + completePendingShipmentsHelper(shipments, shipment_idx + 1, options); + } + } + ], + onSuccess: function(data) { + completePendingShipmentsHelper(shipments, shipment_idx + 1, options); + }, + } + ); + + } else if (options.reload) { + location.reload(); + } +} + /* * Launches a modal form to mark a PurchaseOrder as "complete" */ From f036252fb9c2f3f3522afd0ed9c27237f569bea0 Mon Sep 17 00:00:00 2001 From: Maksim Stojkovic <18454392+maksimstojkovic@users.noreply.github.com> Date: Sat, 21 May 2022 01:31:01 +1000 Subject: [PATCH 9/9] Added completePendingShipments to exported section --- InvenTree/templates/js/translated/order.js | 1 + 1 file changed, 1 insertion(+) diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js index b9b6da3b36..0c21e368f1 100644 --- a/InvenTree/templates/js/translated/order.js +++ b/InvenTree/templates/js/translated/order.js @@ -24,6 +24,7 @@ cancelSalesOrder, completePurchaseOrder, completeShipment, + completePendingShipments, createSalesOrder, createSalesOrderShipment, editPurchaseOrderLineItem,