mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-03 13:58:47 +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 = []
|
rows = []
|
||||||
|
errors = []
|
||||||
|
|
||||||
headers = self.dataset.headers
|
headers = self.dataset.headers
|
||||||
|
|
||||||
@ -875,6 +876,8 @@ class BomExtractSerializer(serializers.Serializer):
|
|||||||
|
|
||||||
for row in self.dataset.dict:
|
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!
|
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)
|
queryset = queryset.filter(IPN=part_ipn)
|
||||||
|
|
||||||
# Only if we have a single direct match
|
# Only if we have a single direct match
|
||||||
if queryset.exists() and queryset.count() == 1:
|
if queryset.exists():
|
||||||
part = queryset.first()
|
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
|
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)
|
row[field_name] = self.find_matching_data(row, field_name, self.dataset.headers)
|
||||||
|
|
||||||
rows.append(row)
|
rows.append(row)
|
||||||
|
errors.append(error)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'rows': rows,
|
'rows': rows,
|
||||||
|
'errors': errors,
|
||||||
'headers': headers,
|
'headers': headers,
|
||||||
'filename': self.filename,
|
'filename': self.filename,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user