mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 19:46:46 +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'^adjust/?', views.StockAdjust.as_view(), name='stock-adjust'),
|
||||||
|
|
||||||
|
url(r'^export/?', views.StockExport.as_view(), name='stock-export'),
|
||||||
|
|
||||||
# Individual stock items
|
# Individual stock items
|
||||||
url(r'^item/(?P<pk>\d+)/', include(stock_item_detail_urls)),
|
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 AjaxUpdateView, AjaxDeleteView, AjaxCreateView
|
||||||
from InvenTree.views import QRCodeView
|
from InvenTree.views import QRCodeView
|
||||||
|
|
||||||
from InvenTree.helpers import str2bool
|
from InvenTree.helpers import str2bool, DownloadFile
|
||||||
from InvenTree.helpers import ExtractSerialNumbers
|
from InvenTree.helpers import ExtractSerialNumbers
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@ -119,6 +119,42 @@ class StockLocationQRCode(QRCodeView):
|
|||||||
return None
|
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):
|
class StockItemQRCode(QRCodeView):
|
||||||
""" View for displaying a QR code for a StockItem object """
|
""" View for displaying a QR code for a StockItem object """
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user