mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Return per-row error messages when extracting data
This commit is contained in:
parent
29c3064ae7
commit
a9e1357ffb
@ -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,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user