mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Form / view for downloading stocktake info
This commit is contained in:
parent
f4e71d6055
commit
faf8b9f2f0
@ -96,6 +96,37 @@ class SerializeStockForm(forms.ModelForm):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class ExportOptionsForm(HelperForm):
|
||||||
|
""" Form for selecting stock export options """
|
||||||
|
|
||||||
|
file_format = forms.ChoiceField(label=_('File Format'), help_text=_('Select output file format'))
|
||||||
|
|
||||||
|
include_sublocations = forms.BooleanField(required=False, initial=True, help_text=_("Include stock items in sub locations"))
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = StockLocation
|
||||||
|
fields = [
|
||||||
|
'file_format',
|
||||||
|
'include_sublocations',
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_format_choices(self):
|
||||||
|
""" File format choices """
|
||||||
|
|
||||||
|
choices = [
|
||||||
|
('csv', 'CSV'),
|
||||||
|
('xls', 'XLS'),
|
||||||
|
('xlsx', 'XLSX'),
|
||||||
|
]
|
||||||
|
|
||||||
|
return choices
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
self.fields['file_format'].choices = self.get_format_choices()
|
||||||
|
|
||||||
|
|
||||||
class AdjustStockForm(forms.ModelForm):
|
class AdjustStockForm(forms.ModelForm):
|
||||||
""" Form for performing simple stock adjustments.
|
""" Form for performing simple stock adjustments.
|
||||||
|
|
||||||
|
@ -70,6 +70,25 @@
|
|||||||
sessionStorage.removeItem('inventree-show-part-locations');
|
sessionStorage.removeItem('inventree-show-part-locations');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#location-export").click(function() {
|
||||||
|
launchModalForm("{% url 'stock-export-options' %}",
|
||||||
|
{
|
||||||
|
success: function(response) {
|
||||||
|
var url = "{% url 'stock-export' %}";
|
||||||
|
|
||||||
|
url += "?format=" + response.format;
|
||||||
|
url += "&cascade=" + response.cascade;
|
||||||
|
|
||||||
|
{% if location %}
|
||||||
|
url += "&location={{ location.id }}";
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
location.href = url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
$('#location-create').click(function () {
|
$('#location-create').click(function () {
|
||||||
launchModalForm("{% url 'stock-location-create' %}",
|
launchModalForm("{% url 'stock-location-create' %}",
|
||||||
{
|
{
|
||||||
|
@ -51,6 +51,7 @@ 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-options/?', views.StockExportOptions.as_view(), name='stock-export-options'),
|
||||||
url(r'^export/?', views.StockExport.as_view(), name='stock-export'),
|
url(r'^export/?', views.StockExport.as_view(), name='stock-export'),
|
||||||
|
|
||||||
# Individual stock items
|
# Individual stock items
|
||||||
|
@ -31,6 +31,7 @@ from .forms import EditStockItemForm
|
|||||||
from .forms import AdjustStockForm
|
from .forms import AdjustStockForm
|
||||||
from .forms import TrackingEntryForm
|
from .forms import TrackingEntryForm
|
||||||
from .forms import SerializeStockForm
|
from .forms import SerializeStockForm
|
||||||
|
from .forms import ExportOptionsForm
|
||||||
|
|
||||||
|
|
||||||
class StockIndex(ListView):
|
class StockIndex(ListView):
|
||||||
@ -119,6 +120,38 @@ class StockLocationQRCode(QRCodeView):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class StockExportOptions(AjaxView):
|
||||||
|
""" Form for selecting StockExport options """
|
||||||
|
|
||||||
|
model = StockLocation
|
||||||
|
ajax_form_title = 'Stock Export Options'
|
||||||
|
form_class = ExportOptionsForm
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
|
||||||
|
self.request = request
|
||||||
|
|
||||||
|
fmt = request.POST.get('file_format', 'csv').lower()
|
||||||
|
cascade = str2bool(request.POST.get('include_sublocations', True))
|
||||||
|
|
||||||
|
# Format a URL to redirect to
|
||||||
|
url = reverse('stock-export')
|
||||||
|
|
||||||
|
url += '?format=' + fmt
|
||||||
|
url += '&cascade=' + str(cascade)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'form_valid': True,
|
||||||
|
'format': fmt,
|
||||||
|
'cascade': cascade
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.renderJsonResponse(self.request, self.form_class(), data=data)
|
||||||
|
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
return self.renderJsonResponse(request, self.form_class())
|
||||||
|
|
||||||
|
|
||||||
class StockExport(AjaxView):
|
class StockExport(AjaxView):
|
||||||
""" Export stock data from a particular location.
|
""" Export stock data from a particular location.
|
||||||
Returns a file containing stock information for that location.
|
Returns a file containing stock information for that location.
|
||||||
|
Loading…
Reference in New Issue
Block a user