From e7c25126a48a893d7ac363924bf94d9bd2405994 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 26 Oct 2021 00:17:17 +1100 Subject: [PATCH] Construct table of "shipments" --- InvenTree/order/api.py | 2 +- .../migrations/0055_auto_20211025_0645.py | 3 + .../templates/order/sales_order_detail.html | 43 ++++++ .../order/templates/order/so_navbar.html | 7 + InvenTree/templates/js/translated/order.js | 122 +++++++++++++++++- 5 files changed, 170 insertions(+), 7 deletions(-) diff --git a/InvenTree/order/api.py b/InvenTree/order/api.py index 80708c9922..954295ef8e 100644 --- a/InvenTree/order/api.py +++ b/InvenTree/order/api.py @@ -810,7 +810,7 @@ order_api_urls = [ ])), url(r'^shipment/', include([ - url(r'^(?P\d)+/', include([ + url(r'^(?P\d+)/', include([ url(r'^.*$', SOShipmentDetail.as_view(), name='api-so-shipment-detail'), ])), url(r'^.*$', SOShipmentList.as_view(), name='api-so-shipment-list'), diff --git a/InvenTree/order/migrations/0055_auto_20211025_0645.py b/InvenTree/order/migrations/0055_auto_20211025_0645.py index 13ea184cfe..d45e92aead 100644 --- a/InvenTree/order/migrations/0055_auto_20211025_0645.py +++ b/InvenTree/order/migrations/0055_auto_20211025_0645.py @@ -41,6 +41,9 @@ def add_shipment(apps, schema_editor): order=order, ) + if order.status == SalesOrderStatus.SHIPPED: + shipment.shipment_date = order.shipment_date + shipment.save() # Iterate through each allocation associated with this order diff --git a/InvenTree/order/templates/order/sales_order_detail.html b/InvenTree/order/templates/order/sales_order_detail.html index cddba74cd6..87b6d80acf 100644 --- a/InvenTree/order/templates/order/sales_order_detail.html +++ b/InvenTree/order/templates/order/sales_order_detail.html @@ -33,6 +33,32 @@ +
+ {% if order.is_pending %} +
+

{% trans "Pending Shipments" %}

+
+
+ {% if roles.sales_order.change %} +
+
+ +
+
+ {% endif %} +
+
+ {% endif %} +
+

{% trans "Completed Shipments" %}

+
+
+
+
+
+

{% trans "Build Orders" %}

@@ -79,6 +105,23 @@ {% block js_ready %} {{ block.super }} + // Callback when the "shipments" panel is first loaded + onPanelLoad('order-shipments', function() { + + {% if order.is_pending %} + loadSalesOrderShipmentTable('#pending-shipments-table', { + order: {{ order.pk }}, + shipped: false, + }); + {% endif %} + + loadSalesOrderShipmentTable('#completed-shipments-table', { + order: {{ order.pk }}, + shipped: true, + }); + + }); + $('#edit-notes').click(function() { constructForm('{% url "api-so-detail" order.pk %}', { fields: { diff --git a/InvenTree/order/templates/order/so_navbar.html b/InvenTree/order/templates/order/so_navbar.html index 710976ed3f..814df0fca6 100644 --- a/InvenTree/order/templates/order/so_navbar.html +++ b/InvenTree/order/templates/order/so_navbar.html @@ -16,6 +16,13 @@ +
  • + + + {% trans "Shipments" %} + +
  • +
  • diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js index e55371703c..6e69eb6a02 100644 --- a/InvenTree/templates/js/translated/order.js +++ b/InvenTree/templates/js/translated/order.js @@ -26,6 +26,7 @@ loadPurchaseOrderTable, loadSalesOrderAllocationTable, loadSalesOrderLineItemTable, + loadSalesOrderShipmentTable, loadSalesOrderTable, newPurchaseOrderFromOrderWizard, newSupplierPartFromOrderWizard, @@ -1100,6 +1101,117 @@ function loadSalesOrderTable(table, options) { } +/* + * Load a table displaying Shipment information against a particular order + */ +function loadSalesOrderShipmentTable(table, options={}) { + + options.table = table; + + options.params = options.params || {}; + + // Filter by order + options.params.order = options.order; + + // Filter by "shipped" status + options.params.shipped = options.shipped || false; + + var filters = loadTableFilters('salesordershipment'); + + for (var key in options.params) { + filters[key] = options.params[key]; + } + + var todo = "Setup filter list for this table"; + + function makeShipmentActions(row) { + // Construct "actions" for the given shipment row + var pk = row.pk; + + var html = `
    `; + + html += makeIconButton('fa-edit icon-blue', 'button-shipment-edit', pk, '{% trans "Edit shipment" %}'); + + html += `
    `; + + return html; + + } + + function setupShipmentCallbacks() { + // Setup action button callbacks + + $(table).find('.button-shipment-edit').click(function() { + var pk = $(this).attr('pk'); + + constructForm(`/api/order/so/shipment/${pk}/`, { + fields: { + reference: {}, + }, + title: '{% trans "Edit Shipment" %}', + onSuccess: function() { + $(table).bootstrapTable('refresh'); + } + }); + }); + } + + $(table).inventreeTable({ + url: '{% url "api-so-shipment-list" %}', + queryParams: filters, + original: options.params, + name: options.name || 'salesordershipment', + search: false, + paginationVAlign: 'bottom', + showColumns: true, + detailView: true, + detailViewByClick: false, + detailFilter: function(index, row) { + return row.allocations.length > 0; + }, + detailFormatter: function(index, row, element) { + return showAllocationSubTable(index, row, element, options); + }, + onPostBody: setupShipmentCallbacks, + formatNoMatches: function() { + return '{% trans "No matching shipments found" %}'; + }, + columns: [ + { + visible: false, + checkbox: true, + switchable: false, + }, + { + field: 'reference', + title: '{% trans "Reference" %}', + switchable: false, + }, + { + field: 'shipment_date', + title: '{% trans "Shipment Date" %}', + visible: options.shipped, + switchable: false, + }, + { + field: 'notes', + title: '{% trans "Notes" %}', + visible: false, + // TODO: Implement 'notes' field + }, + { + title: '', + switchable: false, + formatter: function(value, row) { + return makeShipmentActions(row); + } + } + ], + }); +} + + + function loadSalesOrderAllocationTable(table, options={}) { /** * Load a table with SalesOrderAllocation items @@ -1123,7 +1235,7 @@ function loadSalesOrderAllocationTable(table, options={}) { $(table).inventreeTable({ url: '{% url "api-so-allocation-list" %}', queryParams: filters, - name: 'salesorderallocation', + name: options.name || 'salesorderallocation', groupBy: false, search: false, paginationVAlign: 'bottom', @@ -1198,16 +1310,14 @@ function showAllocationSubTable(index, row, element, options) { // Construct a sub-table element var html = `
    - -
    +
    `; element.html(html); var table = $(`#allocation-table-${row.pk}`); - // Is the parent SalesOrder pending? - var pending = options.status == {{ SalesOrderStatus.PENDING }}; + var shipped = options.shipped; function setupCallbacks() { // Add callbacks for 'edit' buttons @@ -1300,7 +1410,7 @@ function showAllocationSubTable(index, row, element, options) { var html = `
    `; var pk = row.pk; - if (pending) { + if (!shipped) { html += makeIconButton('fa-edit icon-blue', 'button-allocation-edit', pk, '{% trans "Edit stock allocation" %}'); html += makeIconButton('fa-trash-alt icon-red', 'button-allocation-delete', pk, '{% trans "Delete stock allocation" %}'); }