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
This commit is contained in:
Oliver 2021-12-02 21:59:59 +11:00
parent d5ace1a8da
commit e74e7138a9
4 changed files with 29 additions and 6 deletions

View File

@ -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

View File

@ -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):

View File

@ -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 += `</div>`;
@ -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');
}
}
);

View File

@ -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" %}');
}