From efc08f6824ff02af8bc25640d661bcfcf425ec38 Mon Sep 17 00:00:00 2001
From: Oliver Walters <oliver.henry.walters@gmail.com>
Date: Sat, 7 Sep 2019 20:47:02 +1000
Subject: [PATCH 1/3] Improve table sorting for company list

---
 InvenTree/company/templates/company/index.html | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/InvenTree/company/templates/company/index.html b/InvenTree/company/templates/company/index.html
index d4193960d3..17b737b670 100644
--- a/InvenTree/company/templates/company/index.html
+++ b/InvenTree/company/templates/company/index.html
@@ -55,6 +55,7 @@ InvenTree | Supplier List
             {
                 field: 'description',
                 title: 'Description',
+                sortable: true,
             },
             {
                 field: 'website',
@@ -69,6 +70,7 @@ InvenTree | Supplier List
             {
                 field: 'part_count',
                 title: 'Parts',
+                sortable: true,
                 formatter: function(value, row, index, field) {
                     return renderLink(value, row.url + 'parts/');
                 }

From b4bbd43bae20eaa875ab3d6399fadee67350c2e0 Mon Sep 17 00:00:00 2001
From: Oliver Walters <oliver.henry.walters@gmail.com>
Date: Sat, 7 Sep 2019 21:15:14 +1000
Subject: [PATCH 2/3] Fix 404 if a stock item is completely depleted

---
 InvenTree/stock/templates/stock/item.html |  1 +
 InvenTree/stock/views.py                  | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/InvenTree/stock/templates/stock/item.html b/InvenTree/stock/templates/stock/item.html
index 87abe0adfe..e64dcce1c7 100644
--- a/InvenTree/stock/templates/stock/item.html
+++ b/InvenTree/stock/templates/stock/item.html
@@ -221,6 +221,7 @@
                     item: {{ item.id }},
                 },
                 reload: true,
+                follow: true,
             }
         );
     }
diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py
index 6ecdf1f3a2..1431cb3693 100644
--- a/InvenTree/stock/views.py
+++ b/InvenTree/stock/views.py
@@ -10,6 +10,7 @@ from django.views.generic.edit import FormMixin
 from django.views.generic import DetailView, ListView
 from django.forms.models import model_to_dict
 from django.forms import HiddenInput
+from django.urls import reverse
 
 from django.utils.translation import ugettext as _
 
@@ -310,6 +311,19 @@ class StockAdjust(AjaxView, FormMixin):
 
             data['success'] = result
 
+            # Special case - Single Stock Item
+            # If we deplete the stock item, we MUST redirect to a new view
+            single_item = len(self.stock_items) == 1
+
+            if result and single_item:
+
+                # Was the entire stock taken?
+                item = self.stock_items[0]
+                
+                if item.quantity == 0:
+                    # Instruct the form to redirect
+                    data['url'] = reverse('stock-index')
+
         return self.renderJsonResponse(request, form, data=data)
 
     def do_action(self):

From 023c386f5ee580139c4aad33ee48641cdc3656f9 Mon Sep 17 00:00:00 2001
From: Oliver Walters <oliver.henry.walters@gmail.com>
Date: Sat, 7 Sep 2019 21:18:32 +1000
Subject: [PATCH 3/3] Display a warning message if delete_on_deplete is set

---
 InvenTree/stock/templates/stock/item.html | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/InvenTree/stock/templates/stock/item.html b/InvenTree/stock/templates/stock/item.html
index e64dcce1c7..7bf6ff4e29 100644
--- a/InvenTree/stock/templates/stock/item.html
+++ b/InvenTree/stock/templates/stock/item.html
@@ -49,6 +49,10 @@
     <div class='alert alert-block alert-info'>
         This stock item is serialized - it has a unique serial number and the quantity cannot be adjusted.
     </div>
+    {% elif item.delete_on_deplete %}
+    <div class='alert alert-block alert-warning'>
+        This stock item will be automatically deleted when all stock is depleted.
+    </div>
     {% endif %}
 </div>