2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-09-13 14:11:37 +00:00

Bom export fix (#10163)

* Bug fix for BOM exporter

- Handle edge case with null manufacturer value

* Mark failed data exports
This commit is contained in:
Oliver
2025-08-12 12:54:30 +10:00
committed by GitHub
parent e82965ee6d
commit ae5716d625
2 changed files with 21 additions and 6 deletions

View File

@@ -351,10 +351,13 @@ class DataExportViewMixin:
filename = export_plugin.generate_filename(
serializer_class.Meta.model, export_format
)
except Exception:
except Exception as e:
InvenTree.exceptions.log_error(
'generate_filename', plugin=export_plugin.slug
)
output.mark_failure(error=str(e))
raise ValidationError(export_error)
# The provided plugin is responsible for exporting the data
@@ -364,8 +367,12 @@ class DataExportViewMixin:
queryset, serializer_class, headers, export_context, output
)
except Exception:
except Exception as e:
InvenTree.exceptions.log_error('export_data', plugin=export_plugin.slug)
# Log the error against the output object
output.mark_failure(error=str(e))
raise ValidationError(export_error)
if not isinstance(data, list):
@@ -377,17 +384,21 @@ class DataExportViewMixin:
if hasattr(export_plugin, 'update_headers'):
try:
headers = export_plugin.update_headers(headers, export_context)
except Exception:
except Exception as e:
InvenTree.exceptions.log_error(
'update_headers', plugin=export_plugin.slug
)
output.mark_failure(error=str(e))
raise ValidationError(export_error)
# Now, export the data to file
try:
datafile = serializer.export_to_file(data, headers, export_format)
except Exception:
except Exception as e:
InvenTree.exceptions.log_error('export_to_file', plugin=export_plugin.slug)
output.mark_failure(error=str(e))
raise ValidationError(_('Error occurred during data export'))
# Update the output object with the exported data

View File

@@ -275,7 +275,9 @@ class BomExporterPlugin(DataExportMixin, InvenTreePlugin):
for supplier_part in bom_item.sub_part.supplier_parts.all():
manufacturer_part = supplier_part.manufacturer_part
supplier_part_data.update({
f'supplier_name_{idx}': supplier_part.supplier.name,
f'supplier_name_{idx}': supplier_part.supplier.name
if supplier_part.supplier
else '',
f'supplier_sku_{idx}': supplier_part.SKU,
f'supplier_mpn_{idx}': manufacturer_part.MPN
if manufacturer_part
@@ -296,7 +298,9 @@ class BomExporterPlugin(DataExportMixin, InvenTreePlugin):
for manufacturer_part in bom_item.sub_part.manufacturer_parts.all():
manufacturer_part_data.update({
f'manufacturer_name_{idx}': manufacturer_part.manufacturer.name,
f'manufacturer_name_{idx}': manufacturer_part.manufacturer.name
if manufacturer_part.manufacturer
else '',
f'manufacturer_mpn_{idx}': manufacturer_part.MPN,
})