diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index 490237eb34..38a2bd443f 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -868,6 +868,7 @@ class BomExtractSerializer(serializers.Serializer): """ rows = [] + errors = [] headers = self.dataset.headers @@ -875,6 +876,8 @@ class BomExtractSerializer(serializers.Serializer): for row in self.dataset.dict: + error = {} + """ If the "level" column is specified, and this is not a top-level BOM item, ignore the row! """ @@ -929,8 +932,15 @@ class BomExtractSerializer(serializers.Serializer): queryset = queryset.filter(IPN=part_ipn) # Only if we have a single direct match - if queryset.exists() and queryset.count() == 1: - part = queryset.first() + if queryset.exists(): + if queryset.count() == 1: + part = queryset.first() + else: + # Multiple matches! + error['part'] = _('Multiple matching parts found') + + if part is None and 'part' not in error: + error['part'] = _('No matching part found') row['part'] = part.pk if part is not None else None @@ -940,9 +950,11 @@ class BomExtractSerializer(serializers.Serializer): row[field_name] = self.find_matching_data(row, field_name, self.dataset.headers) rows.append(row) + errors.append(error) return { 'rows': rows, + 'errors': errors, 'headers': headers, 'filename': self.filename, }