Add a form to select export format

This commit is contained in:
Oliver 2021-10-07 13:33:10 +11:00
parent d391c5059b
commit 64cf916c50
5 changed files with 76 additions and 23 deletions

View File

@ -39,6 +39,9 @@ src="{% static 'img/blank_image.png' %}"
<button type='button' class='btn btn-default' id='print-order-report' title='{% trans "Print" %}'>
<span class='fas fa-print'></span>
</button>
<button type='button' class='btn btn-default' id='export-order' title='{% trans "Export order to file" %}'>
<span class='fas fa-file-download'></span>
</button>
{% if roles.purchase_order.change %}
<button type='button' class='btn btn-default' id='edit-order' title='{% trans "Edit order information" %}'>
<span class='fas fa-edit icon-green'></span>
@ -61,9 +64,6 @@ src="{% static 'img/blank_image.png' %}"
</button>
{% endif %}
{% endif %}
<button type='button' class='btn btn-default' id='export-order' title='{% trans "Export order to file" %}'>
<span class='fas fa-file-download'></span>
</button>
</div>
</div>
{% endblock %}
@ -224,7 +224,7 @@ $("#cancel-order").click(function() {
});
$("#export-order").click(function() {
location.href = '{% url "po-export" order.id %}';
exportOrder('{% url "po-export" order.id %}');
});

View File

@ -202,7 +202,7 @@ $('#print-order-report').click(function() {
});
$('#export-order').click(function() {
location.href = '{% url "so-export" order.id %}';
exportOrder('{% url "so-export" order.id %}');
});
{% endblock %}

View File

@ -10,6 +10,7 @@
/* exported
attachClipboard,
enableDragAndDrop,
exportFormatOptions,
inventreeDocReady,
inventreeLoad,
inventreeSave,
@ -46,6 +47,31 @@ function attachClipboard(selector, containerselector, textElement) {
}
/**
* Return a standard list of export format options *
*/
function exportFormatOptions() {
return [
{
value: 'csv',
display_name: 'CSV',
},
{
value: 'tsv',
display_name: 'TSV',
},
{
value: 'xls',
display_name: 'XLS',
},
{
value: 'xlsx',
display_name: 'XLSX',
},
];
}
function inventreeDocReady() {
/* Run this function when the HTML document is loaded.
* This will be called for every page that extends "base.html"

View File

@ -21,6 +21,7 @@
/* exported
createSalesOrder,
editPurchaseOrderLineItem,
exportOrder,
loadPurchaseOrderLineItemTable,
loadPurchaseOrderTable,
loadSalesOrderAllocationTable,
@ -187,6 +188,49 @@ function newSupplierPartFromOrderWizard(e) {
});
}
/**
* Export an order (PurchaseOrder or SalesOrder)
*
* - Display a simple form which presents the user with export options
*
*/
function exportOrder(redirect_url, options={}) {
var format = options.format;
// If default format is not provided, lookup
if (!format) {
format = inventreeLoad('order-export-format', 'csv');
}
constructFormBody({}, {
title: '{% trans "Export Order" %}',
fields: {
format: {
label: '{% trans "Format" %}',
help_text: '{% trans "Select file format" %}',
required: true,
type: 'choice',
value: format,
choices: exportFormatOptions(),
}
},
onSubmit: function(fields, opts) {
var format = getFormFieldValue('format', fields['format'], opts);
// Save the format for next time
inventreeSave('order-export-format', format);
// Hide the modal
$(opts.modal).modal('hide');
// Download the file!
location.href = `${redirect_url}?format=${format}`;
}
});
}
function newPurchaseOrderFromOrderWizard(e) {
/* Create a new purchase order directly from an order form.
* Launches a secondary modal and (if successful),

View File

@ -98,24 +98,7 @@ function exportStock(params={}) {
required: true,
type: 'choice',
value: 'csv',
choices: [
{
value: 'csv',
display_name: 'CSV',
},
{
value: 'tsv',
display_name: 'TSV',
},
{
value: 'xls',
display_name: 'XLS',
},
{
value: 'xlsx',
display_name: 'XLSX',
},
],
choices: exportFormatOptions(),
},
sublocations: {
label: '{% trans "Include Sublocations" %}',