From 9212d6047ff7b5ccd14241a745d2f2b07a052191 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 8 Sep 2019 23:10:13 +1000 Subject: [PATCH] Add supplier information to exported data --- InvenTree/InvenTree/helpers.py | 12 ++++++++++++ InvenTree/stock/forms.py | 7 ++----- InvenTree/stock/templates/stock/location.html | 1 + InvenTree/stock/views.py | 10 ++++++++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/InvenTree/InvenTree/helpers.py b/InvenTree/InvenTree/helpers.py index 887b443544..84409226c2 100644 --- a/InvenTree/InvenTree/helpers.py +++ b/InvenTree/InvenTree/helpers.py @@ -94,6 +94,18 @@ def MakeBarcode(object_type, object_id, object_url, data={}): return json.dumps(data, sort_keys=True) +def GetExportFormats(): + """ Return a list of allowable file formats for exporting data """ + + return [ + 'csv', + 'tsv', + 'xls', + 'xlsx', + 'json', + ] + + def DownloadFile(data, filename, content_type='application/text'): """ Create a dynamic file for the user to download. diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index fe9de3cac2..3a34e0416d 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -9,6 +9,7 @@ from django import forms from django.forms.utils import ErrorDict from django.utils.translation import ugettext as _ +from InvenTree.helpers import GetExportFormats from InvenTree.forms import HelperForm from .models import StockLocation, StockItem, StockItemTracking @@ -113,11 +114,7 @@ class ExportOptionsForm(HelperForm): def get_format_choices(self): """ File format choices """ - choices = [ - ('csv', 'CSV'), - ('xls', 'XLS'), - ('xlsx', 'XLSX'), - ] + choices = [(x, x.upper()) for x in GetExportFormats()] return choices diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index cad986c097..fa0db9efce 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -73,6 +73,7 @@ $("#location-export").click(function() { launchModalForm("{% url 'stock-export-options' %}", { + submit_text: "Export", success: function(response) { var url = "{% url 'stock-export' %}"; diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index f3d133e1d0..ab482b38f8 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, DownloadFile +from InvenTree.helpers import str2bool, DownloadFile, GetExportFormats from InvenTree.helpers import ExtractSerialNumbers from datetime import datetime @@ -177,7 +177,7 @@ class StockExport(AjaxView): location = None - if export_format not in ['csv', 'xls', 'xslx']: + if export_format not in GetExportFormats(): export_format = 'csv' filename = 'InvenTree_Stocktake_{loc}_{date}.{fmt}'.format( @@ -203,6 +203,8 @@ class StockExport(AjaxView): _('Part ID'), _('Part'), _('Supplier Part ID'), + _('Supplier ID'), + _('Supplier'), _('Location ID'), _('Location'), _('Quantity'), @@ -228,8 +230,12 @@ class StockExport(AjaxView): if item.supplier_part: line.append(item.supplier_part.pk) + line.append(item.supplier_part.supplier.pk) + line.append(item.supplier_part.supplier.name) else: line.append('') + line.append('') + line.append('') line.append(item.location.pk) line.append(item.location.name)