mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add option for including supplier data for BOM export
This commit is contained in:
parent
965dba4739
commit
d0b5550c86
@ -47,7 +47,7 @@ def MakeBomTemplate(fmt):
|
|||||||
return DownloadFile(data, filename)
|
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.
|
""" Export a BOM (Bill of Materials) for a given part.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -92,6 +92,11 @@ def ExportBom(part, fmt='csv', cascade=False, max_levels=None):
|
|||||||
|
|
||||||
dataset = BomItemResource().export(queryset=bom_items, cascade=cascade)
|
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
|
# Expand dataset with manufacturer parts
|
||||||
manufacturer_headers = [
|
manufacturer_headers = [
|
||||||
_('Supplier'),
|
_('Supplier'),
|
||||||
|
@ -54,10 +54,12 @@ class BomExportForm(forms.Form):
|
|||||||
|
|
||||||
file_format = forms.ChoiceField(label=_("File Format"), help_text=_("Select output file format"))
|
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)"))
|
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):
|
def get_choices(self):
|
||||||
""" BOM export format choices """
|
""" BOM export format choices """
|
||||||
|
|
||||||
|
@ -1499,6 +1499,8 @@ class BomDownload(AjaxView):
|
|||||||
|
|
||||||
cascade = str2bool(request.GET.get('cascade', False))
|
cascade = str2bool(request.GET.get('cascade', False))
|
||||||
|
|
||||||
|
supplier_data = str2bool(request.GET.get('supplier_data', False))
|
||||||
|
|
||||||
levels = request.GET.get('levels', None)
|
levels = request.GET.get('levels', None)
|
||||||
|
|
||||||
if levels is not None:
|
if levels is not None:
|
||||||
@ -1514,7 +1516,7 @@ class BomDownload(AjaxView):
|
|||||||
if not IsValidBOMFormat(export_format):
|
if not IsValidBOMFormat(export_format):
|
||||||
export_format = 'csv'
|
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):
|
def get_data(self):
|
||||||
return {
|
return {
|
||||||
@ -1539,6 +1541,7 @@ class BomExport(AjaxView):
|
|||||||
fmt = request.POST.get('file_format', 'csv').lower()
|
fmt = request.POST.get('file_format', 'csv').lower()
|
||||||
cascade = str2bool(request.POST.get('cascading', False))
|
cascade = str2bool(request.POST.get('cascading', False))
|
||||||
levels = request.POST.get('levels', None)
|
levels = request.POST.get('levels', None)
|
||||||
|
supplier_data = str2bool(request.POST.get('supplier_data', False))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
part = Part.objects.get(pk=self.kwargs['pk'])
|
part = Part.objects.get(pk=self.kwargs['pk'])
|
||||||
@ -1553,6 +1556,7 @@ class BomExport(AjaxView):
|
|||||||
|
|
||||||
url += '?file_format=' + fmt
|
url += '?file_format=' + fmt
|
||||||
url += '&cascade=' + str(cascade)
|
url += '&cascade=' + str(cascade)
|
||||||
|
url += '&supplier_data=' + str(supplier_data)
|
||||||
|
|
||||||
if levels:
|
if levels:
|
||||||
url += '&levels=' + str(levels)
|
url += '&levels=' + str(levels)
|
||||||
|
Loading…
Reference in New Issue
Block a user