mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
parent
88fc0393b7
commit
01ce752a8c
@ -55,36 +55,6 @@ class PartImageDownloadForm(HelperForm):
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class BomExportForm(forms.Form):
|
|
||||||
""" Simple form to let user set BOM export options,
|
|
||||||
before exporting a BOM (bill of materials) file.
|
|
||||||
"""
|
|
||||||
|
|
||||||
file_format = forms.ChoiceField(label=_("File Format"), help_text=_("Select output file format"))
|
|
||||||
|
|
||||||
cascading = forms.BooleanField(label=_("Cascading"), required=False, initial=True, help_text=_("Download cascading / multi-level BOM"))
|
|
||||||
|
|
||||||
levels = forms.IntegerField(label=_("Levels"), required=True, initial=0, help_text=_("Select maximum number of BOM levels to export (0 = all levels)"))
|
|
||||||
|
|
||||||
parameter_data = forms.BooleanField(label=_("Include Parameter Data"), required=False, initial=False, help_text=_("Include part parameters data in exported BOM"))
|
|
||||||
|
|
||||||
stock_data = forms.BooleanField(label=_("Include Stock Data"), required=False, initial=False, help_text=_("Include part stock data in exported BOM"))
|
|
||||||
|
|
||||||
manufacturer_data = forms.BooleanField(label=_("Include Manufacturer Data"), required=False, initial=True, help_text=_("Include part manufacturer data in exported BOM"))
|
|
||||||
|
|
||||||
supplier_data = forms.BooleanField(label=_("Include Supplier Data"), required=False, initial=True, help_text=_("Include part supplier data in exported BOM"))
|
|
||||||
|
|
||||||
def get_choices(self):
|
|
||||||
""" BOM export format choices """
|
|
||||||
|
|
||||||
return [(x, x.upper()) for x in GetExportFormats()]
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super().__init__(*args, **kwargs)
|
|
||||||
|
|
||||||
self.fields['file_format'].choices = self.get_choices()
|
|
||||||
|
|
||||||
|
|
||||||
class BomDuplicateForm(HelperForm):
|
class BomDuplicateForm(HelperForm):
|
||||||
"""
|
"""
|
||||||
Simple confirmation form for BOM duplication.
|
Simple confirmation form for BOM duplication.
|
||||||
|
@ -620,13 +620,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$("#download-bom").click(function () {
|
$("#download-bom").click(function () {
|
||||||
launchModalForm("{% url 'bom-export' part.id %}",
|
exportBom({{ part.id }});
|
||||||
{
|
|
||||||
success: function(response) {
|
|
||||||
location.href = response.url;
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
{% if report_enabled %}
|
{% if report_enabled %}
|
||||||
|
@ -1192,14 +1192,10 @@ class BomExport(AjaxView):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
model = Part
|
model = Part
|
||||||
form_class = part_forms.BomExportForm
|
|
||||||
ajax_form_title = _("Export Bill of Materials")
|
ajax_form_title = _("Export Bill of Materials")
|
||||||
|
|
||||||
role_required = 'part.view'
|
role_required = 'part.view'
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
|
||||||
return self.renderJsonResponse(request, self.form_class())
|
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
|
|
||||||
# Extract POSTed form data
|
# Extract POSTed form data
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
/* exported
|
/* exported
|
||||||
downloadBomTemplate,
|
downloadBomTemplate,
|
||||||
|
exportBom,
|
||||||
newPartFromBomWizard,
|
newPartFromBomWizard,
|
||||||
loadBomTable,
|
loadBomTable,
|
||||||
loadUsedInTable,
|
loadUsedInTable,
|
||||||
@ -60,6 +61,86 @@ function downloadBomTemplate(options={}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export BOM (Bill of Materials) for the specified Part instance
|
||||||
|
*/
|
||||||
|
function exportBom(part_id, options={}) {
|
||||||
|
|
||||||
|
constructFormBody({}, {
|
||||||
|
title: '{% trans "Export BOM" %}',
|
||||||
|
fields: {
|
||||||
|
format: {
|
||||||
|
label: '{% trans "Format" %}',
|
||||||
|
help_text: '{% trans "Select file format" %}',
|
||||||
|
required: true,
|
||||||
|
type: 'choice',
|
||||||
|
value: inventreeLoad('bom-export-format', 'csv'),
|
||||||
|
choices: exportFormatOptions(),
|
||||||
|
},
|
||||||
|
cascading: {
|
||||||
|
label: '{% trans "Cascading" %}',
|
||||||
|
help_text: '{% trans "Download cascading / mmulti-level BOM" %}',
|
||||||
|
type: 'boolean',
|
||||||
|
value: inventreeLoad('bom-export-cascading', true),
|
||||||
|
},
|
||||||
|
levels: {
|
||||||
|
label: '{% trans "Levels" %}',
|
||||||
|
help_text: '{% trans "Select maximum number of BOM levels to export (0 = all levels)" %}',
|
||||||
|
type: 'integer',
|
||||||
|
value: 0,
|
||||||
|
min_value: 0,
|
||||||
|
},
|
||||||
|
parameter_data: {
|
||||||
|
label: '{% trans "Include Parameter Data" %}',
|
||||||
|
help_text: '{% trans "Include part parameter data in exported BOM" %}',
|
||||||
|
type: 'boolean',
|
||||||
|
value: inventreeLoad('bom-export-parameter_data', false),
|
||||||
|
},
|
||||||
|
stock_data: {
|
||||||
|
label: '{% trans "Include Stock Data" %}',
|
||||||
|
help_text: '{% trans "Include part stock data in exported BOM" %}',
|
||||||
|
type: 'boolean',
|
||||||
|
value: inventreeLoad('bom-export-stock_data', false),
|
||||||
|
},
|
||||||
|
manufacturer_data: {
|
||||||
|
label: '{% trans "Include Manufacturer Data" %}',
|
||||||
|
help_text: '{% trans "Include part manufacturer data in exported BOM" %}',
|
||||||
|
type: 'boolean',
|
||||||
|
value: inventreeLoad('bom-export-manufacturer_data', false),
|
||||||
|
},
|
||||||
|
supplier_data: {
|
||||||
|
label: '{% trans "Include Supplier Data" %}',
|
||||||
|
help_text: '{% trans "Include part supplier data in exported BOM" %}',
|
||||||
|
type: 'boolean',
|
||||||
|
value: inventreeLoad('bom-export-supplier_data', false),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onSubmit: function(fields, opts) {
|
||||||
|
|
||||||
|
// Extract values from the form
|
||||||
|
var field_names = ['format', 'cascading', 'levels', 'parameter_data', 'stock_data', 'manufacturer_data', 'supplier_data'];
|
||||||
|
|
||||||
|
var url = `/part/${part_id}/bom-download/?`;
|
||||||
|
|
||||||
|
field_names.forEach(function(fn) {
|
||||||
|
var val = getFormFieldValue(fn, fields[fn], opts);
|
||||||
|
|
||||||
|
// Update user preferences
|
||||||
|
inventreeSave(`bom-export-${fn}`, val);
|
||||||
|
|
||||||
|
url += `${fn}=${val}&`;
|
||||||
|
});
|
||||||
|
|
||||||
|
$(opts.modal).modal('hide');
|
||||||
|
|
||||||
|
// Redirect to the BOM file download
|
||||||
|
location.href = url;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function bomItemFields() {
|
function bomItemFields() {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user