From e74e7138a92c9b5780dbeb7d3cba05b5c4841db1 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 2 Dec 2021 21:59:59 +1100 Subject: [PATCH] More stuff: - Pass tracking number through when completing a shipment - Reload tables automatically when certain actions are performed - Limit stock items to only those with available stock --- InvenTree/order/models.py | 9 ++++++++- InvenTree/order/serializers.py | 5 ++++- InvenTree/templates/js/translated/order.js | 19 ++++++++++++++++--- InvenTree/templates/js/translated/stock.js | 2 +- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index 73f20e77ff..0e5b10cf98 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -956,7 +956,7 @@ class SalesOrderShipment(models.Model): raise ValidationError(_("Shipment has no allocated stock items")) @transaction.atomic - def complete_shipment(self, user): + def complete_shipment(self, user, **kwargs): """ Complete this particular shipment: @@ -979,6 +979,13 @@ class SalesOrderShipment(models.Model): # Update the "shipment" date self.shipment_date = datetime.now() self.shipped_by = user + + # Was a tracking number provided? + tracking_number = kwargs.get('tracking_number', None) + + if tracking_number is not None: + self.tracking_number = tracking_number + self.save() # Finally, check if the order is fully shipped diff --git a/InvenTree/order/serializers.py b/InvenTree/order/serializers.py index 0dddece000..f86aae8163 100644 --- a/InvenTree/order/serializers.py +++ b/InvenTree/order/serializers.py @@ -654,7 +654,10 @@ class SalesOrderShipmentCompleteSerializer(serializers.ModelSerializer): request = self.context['request'] user = request.user - shipment.complete_shipment(user) + # Extract provided tracking number (optional) + tracking_number = data.get('tracking_number', None) + + shipment.complete_shipment(user, tracking_number=tracking_number) class SOShipmentAllocationItemSerializer(serializers.Serializer): diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js index 6dae5cbe79..e44eed9589 100644 --- a/InvenTree/templates/js/translated/order.js +++ b/InvenTree/templates/js/translated/order.js @@ -67,7 +67,10 @@ function completeShipment(shipment_id) { confirm: true, confirmMessage: '{% trans "Confirm Shipment" %}', onSuccess: function(data) { - // TODO + // Reload tables + $('#so-lines-table').bootstrapTable('refresh'); + $('#pending-shipments-table').bootstrapTable('refresh'); + $('#completed-shipments-table').bootstrapTable('refresh'); } }); } @@ -1249,7 +1252,9 @@ function loadSalesOrderShipmentTable(table, options={}) { html += makeIconButton('fa-edit icon-blue', 'button-shipment-edit', pk, '{% trans "Edit shipment" %}'); - html += makeIconButton('fa-truck icon-green', 'button-shipment-ship', pk, '{% trans "Complete shipment" %}'); + if (!options.shipped) { + html += makeIconButton('fa-truck icon-green', 'button-shipment-ship', pk, '{% trans "Complete shipment" %}'); + } html += ``; @@ -1300,7 +1305,10 @@ function loadSalesOrderShipmentTable(table, options={}) { onPostBody: function() { setupShipmentCallbacks(); - $(table).bootstrapTable('expandAllRows'); + // Auto-expand rows on the "pending" table + if (!options.shipped) { + $(table).bootstrapTable('expandAllRows'); + } }, formatNoMatches: function() { return '{% trans "No matching shipments found" %}'; @@ -1557,6 +1565,7 @@ function allocateStockToSalesOrder(order_id, line_items, options={}) { in_stock: true, part_detail: true, location_detail: true, + available: true, }, model: 'stockitem', required: true, @@ -2296,7 +2305,11 @@ function loadSalesOrderLineItemTable(table, options={}) { ], { success: function() { + // Reload this table $(table).bootstrapTable('refresh'); + + // Reload the pending shipment table + $('#pending-shipments-table').bootstrapTable('refresh'); } } ); diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index 0314fff107..d6de4fdd45 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -1282,7 +1282,7 @@ function loadStockTable(table, options) { if (row.serial != null && row.quantity == 1) { html += makeIconBadge('fa-bookmark icon-yellow', '{% trans "Serialized stock item has been allocated" %}'); } else if (row.allocated >= row.quantity) { - html += makeIconBadge('fa-bookmark icon-red', '{% trans "Stock item has been fully allocated" %}'); + html += makeIconBadge('fa-bookmark icon-yellow', '{% trans "Stock item has been fully allocated" %}'); } else { html += makeIconBadge('fa-bookmark', '{% trans "Stock item has been partially allocated" %}'); }