From 2c969ef1c60dfc6854e3e0e92e3f5dd40904a9f4 Mon Sep 17 00:00:00 2001
From: Oliver Walters
Date: Sun, 8 Sep 2019 10:57:19 +1000
Subject: [PATCH 01/12] View for exporting stocktake / stock list
(cherry picked from commit bdad2d6178a14322ef225d08b13db86b6d7d0909)
---
InvenTree/stock/urls.py | 2 ++
InvenTree/stock/views.py | 38 +++++++++++++++++++++++++++++++++++++-
Makefile | 2 +-
3 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/InvenTree/stock/urls.py b/InvenTree/stock/urls.py
index 76fbaae669..19dbecd88a 100644
--- a/InvenTree/stock/urls.py
+++ b/InvenTree/stock/urls.py
@@ -51,6 +51,8 @@ stock_urls = [
url(r'^adjust/?', views.StockAdjust.as_view(), name='stock-adjust'),
+ url(r'^export/?', views.StockExport.as_view(), name='stock-export'),
+
# Individual stock items
url(r'^item/(?P\d+)/', include(stock_item_detail_urls)),
diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py
index 1431cb3693..46d33e534e 100644
--- a/InvenTree/stock/views.py
+++ b/InvenTree/stock/views.py
@@ -18,7 +18,7 @@ from InvenTree.views import AjaxView
from InvenTree.views import AjaxUpdateView, AjaxDeleteView, AjaxCreateView
from InvenTree.views import QRCodeView
-from InvenTree.helpers import str2bool
+from InvenTree.helpers import str2bool, DownloadFile
from InvenTree.helpers import ExtractSerialNumbers
from datetime import datetime
@@ -119,6 +119,42 @@ class StockLocationQRCode(QRCodeView):
return None
+class StockExport(AjaxView):
+ """ Export stock data from a particular location.
+ Returns a file containing stock information for that location.
+ """
+
+ model = StockItem
+
+ def get(self, request, *args, **kwargs):
+
+ location = None
+ loc_id = request.GET.get('location', None)
+ path = 'All-Locations'
+
+ if loc_id:
+ try:
+ location = StockLocation.objects.get(pk=loc_id)
+ path = location.pathstring.replace('/', ':')
+ except (ValueError, StockLocation.DoesNotExist):
+ pass
+
+ export_format = request.GET.get('format', 'csv').lower()
+
+ if export_format not in ['csv', 'xls', 'xslx']:
+ export_format = 'csv'
+
+ filename = 'InvenTree_Stocktake_{loc}_{date}.{fmt}'.format(
+ loc=path,
+ date=datetime.now().strftime("%d-%b-%Y"),
+ fmt=export_format
+ )
+
+ filedata = ""
+
+ return DownloadFile(filedata, filename)
+
+
class StockItemQRCode(QRCodeView):
""" View for displaying a QR code for a StockItem object """
diff --git a/Makefile b/Makefile
index 38446635da..f6b054dab0 100644
--- a/Makefile
+++ b/Makefile
@@ -50,7 +50,7 @@ test:
# Run code coverage
coverage:
python3 InvenTree/manage.py check
- coverage run InvenTree/manage.py test build common company order part stock InvenTree
+ coverage run InvenTree/manage.py test build common company order part stock InvenTree
coverage html
# Install packages required to generate code docs
From f4e71d6055594b5343ef6ce356bd0fffd5aa11b1 Mon Sep 17 00:00:00 2001
From: Oliver Walters
Date: Sun, 8 Sep 2019 10:57:27 +1000
Subject: [PATCH 02/12] Add a buttony-boy
(cherry picked from commit 69ac5d870a2f1bc9589cd9b23212d3b51cf92c80)
---
InvenTree/stock/templates/stock/location.html | 3 +++
1 file changed, 3 insertions(+)
diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html
index 30adba9336..604b91e758 100644
--- a/InvenTree/stock/templates/stock/location.html
+++ b/InvenTree/stock/templates/stock/location.html
@@ -16,6 +16,9 @@
+
{% if location %}
{% include "qr_button.html" %}
@@ -65,13 +86,6 @@ InvenTree | {{ order }}
{% if order.status == OrderStatus.PENDING %}
Add Line Item
{% endif %}
- Edit Order
- {% if order.status == OrderStatus.PENDING and order.lines.count > 0 %}
- Place Order
- {% elif order.status == OrderStatus.PLACED %}
- Receive Items
- {% endif %}
- Export
Order Items
diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py
index ab482b38f8..c831cd76a9 100644
--- a/InvenTree/stock/views.py
+++ b/InvenTree/stock/views.py
@@ -176,7 +176,6 @@ class StockExport(AjaxView):
except (ValueError, StockLocation.DoesNotExist):
location = None
-
if export_format not in GetExportFormats():
export_format = 'csv'
@@ -186,7 +185,6 @@ class StockExport(AjaxView):
fmt=export_format
)
-
if location:
stock_items = location.get_stock_items(cascade)
else:
From e81a4ffacd3c264e0b62417730c6355364450baf Mon Sep 17 00:00:00 2001
From: Oliver Walters
Date: Sun, 8 Sep 2019 23:36:25 +1000
Subject: [PATCH 08/12] Add docs for common modules
---
docs/modules.rst | 2 ++
1 file changed, 2 insertions(+)
diff --git a/docs/modules.rst b/docs/modules.rst
index 06078ad6e2..6509965972 100644
--- a/docs/modules.rst
+++ b/docs/modules.rst
@@ -9,6 +9,7 @@ InvenTree Modules
docs/InvenTree/index
docs/build/index
+ docs/common/index
docs/company/index
docs/part/index
docs/order/index
@@ -18,6 +19,7 @@ The InvenTree Django ecosystem provides the following 'apps' for core functional
* `InvenTree `_ - High level management functions
* `Build `_ - Part build projects
+* `Common `_ - Common modules used by various apps
* `Company `_ - Company management (suppliers / customers)
* `Part `_ - Part management
* `Order `_ - Order management
From 3d5542181aa5c89619b1b659ca0230700b4967f6 Mon Sep 17 00:00:00 2001
From: Oliver Walters
Date: Sun, 8 Sep 2019 23:40:51 +1000
Subject: [PATCH 09/12] Move "Export" button onto stock table
---
InvenTree/stock/templates/stock/location.html | 5 +----
InvenTree/templates/stock_table.html | 1 +
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html
index fa0db9efce..9878aa56f6 100644
--- a/InvenTree/stock/templates/stock/location.html
+++ b/InvenTree/stock/templates/stock/location.html
@@ -16,9 +16,6 @@
-
-
-
{% if location %}
{% include "qr_button.html" %}
@@ -70,7 +67,7 @@
sessionStorage.removeItem('inventree-show-part-locations');
});
- $("#location-export").click(function() {
+ $("#stock-export").click(function() {
launchModalForm("{% url 'stock-export-options' %}",
{
submit_text: "Export",
diff --git a/InvenTree/templates/stock_table.html b/InvenTree/templates/stock_table.html
index e53daa4718..5b707eab24 100644
--- a/InvenTree/templates/stock_table.html
+++ b/InvenTree/templates/stock_table.html
@@ -1,5 +1,6 @@