mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
View for exporting stocktake / stock list
(cherry picked from commit bdad2d6178a14322ef225d08b13db86b6d7d0909)
This commit is contained in:
parent
2f47140e0f
commit
2c969ef1c6
@ -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<pk>\d+)/', include(stock_item_detail_urls)),
|
||||
|
||||
|
@ -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 """
|
||||
|
||||
|
2
Makefile
2
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
|
||||
|
Loading…
Reference in New Issue
Block a user