Add option for including supplier data for BOM export

This commit is contained in:
Oliver Walters 2020-08-19 14:05:16 +10:00
parent 965dba4739
commit d0b5550c86
3 changed files with 64 additions and 53 deletions

View File

@ -47,7 +47,7 @@ def MakeBomTemplate(fmt):
return DownloadFile(data, filename)
def ExportBom(part, fmt='csv', cascade=False, max_levels=None):
def ExportBom(part, fmt='csv', cascade=False, max_levels=None, supplier_data=False):
""" Export a BOM (Bill of Materials) for a given part.
Args:
@ -92,6 +92,11 @@ def ExportBom(part, fmt='csv', cascade=False, max_levels=None):
dataset = BomItemResource().export(queryset=bom_items, cascade=cascade)
if supplier_data:
"""
If requested, add extra columns for each SupplierPart associated with the each line item
"""
# Expand dataset with manufacturer parts
manufacturer_headers = [
_('Supplier'),

View File

@ -54,10 +54,12 @@ class BomExportForm(forms.Form):
file_format = forms.ChoiceField(label=_("File Format"), help_text=_("Select output file format"))
cascading = forms.BooleanField(label=_("Cascading"), required=False, initial=False, help_text=_("Download cascading / multi-level BOM"))
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)"))
supplier_data = forms.BooleanField(label=_("Include Supplier Data"), required=False, initial=True, help_text=_("Include supplier part data in exported BOM"))
def get_choices(self):
""" BOM export format choices """

View File

@ -1499,6 +1499,8 @@ class BomDownload(AjaxView):
cascade = str2bool(request.GET.get('cascade', False))
supplier_data = str2bool(request.GET.get('supplier_data', False))
levels = request.GET.get('levels', None)
if levels is not None:
@ -1514,7 +1516,7 @@ class BomDownload(AjaxView):
if not IsValidBOMFormat(export_format):
export_format = 'csv'
return ExportBom(part, fmt=export_format, cascade=cascade, max_levels=levels)
return ExportBom(part, fmt=export_format, cascade=cascade, max_levels=levels, supplier_data=supplier_data)
def get_data(self):
return {
@ -1539,6 +1541,7 @@ class BomExport(AjaxView):
fmt = request.POST.get('file_format', 'csv').lower()
cascade = str2bool(request.POST.get('cascading', False))
levels = request.POST.get('levels', None)
supplier_data = str2bool(request.POST.get('supplier_data', False))
try:
part = Part.objects.get(pk=self.kwargs['pk'])
@ -1553,6 +1556,7 @@ class BomExport(AjaxView):
url += '?file_format=' + fmt
url += '&cascade=' + str(cascade)
url += '&supplier_data=' + str(supplier_data)
if levels:
url += '&levels=' + str(levels)