mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Raise error if imported dataset contains no data rows
This commit is contained in:
parent
692039f712
commit
29c3064ae7
@ -857,6 +857,9 @@ class BomExtractSerializer(serializers.Serializer):
|
||||
if not part_match:
|
||||
raise serializers.ValidationError(_("No part column found"))
|
||||
|
||||
if len(self.dataset) == 0:
|
||||
raise serializers.ValidationError(_("No data rows found"))
|
||||
|
||||
return bom_file
|
||||
|
||||
def extract_data(self):
|
||||
@ -931,6 +934,11 @@ class BomExtractSerializer(serializers.Serializer):
|
||||
|
||||
row['part'] = part.pk if part is not None else None
|
||||
|
||||
# For each "optional" column, ensure the column names are allocated correctly
|
||||
for field_name in self.OPTIONAL_COLUMNS:
|
||||
if field_name not in row:
|
||||
row[field_name] = self.find_matching_data(row, field_name, self.dataset.headers)
|
||||
|
||||
rows.append(row)
|
||||
|
||||
return {
|
||||
|
@ -122,14 +122,11 @@ class BomUploadTest(InvenTreeAPITestCase):
|
||||
'banana',
|
||||
]
|
||||
|
||||
dataset.append(['test', 'test'])
|
||||
dataset.append(['hello', 'world'])
|
||||
|
||||
response = self.post_bom(
|
||||
'test.csv',
|
||||
bytes(dataset.csv, 'utf8'),
|
||||
expected_code=400,
|
||||
content_type='text/csv',
|
||||
expected_code=400,
|
||||
)
|
||||
|
||||
self.assertIn("Missing required column: 'quantity'", str(response.data))
|
||||
@ -143,3 +140,27 @@ class BomUploadTest(InvenTreeAPITestCase):
|
||||
)
|
||||
|
||||
self.assertIn("Missing required column: 'quantity'", str(response.data))
|
||||
|
||||
# Add the quantity field (or close enough)
|
||||
dataset.headers.append('quAntiTy ')
|
||||
|
||||
response = self.post_bom(
|
||||
'test.csv',
|
||||
bytes(dataset.csv, 'utf8'),
|
||||
content_type='text/csv',
|
||||
expected_code=400,
|
||||
)
|
||||
|
||||
self.assertIn('No part column found', str(response.data))
|
||||
|
||||
dataset.headers.append('part_id')
|
||||
dataset.headers.append('part_name')
|
||||
|
||||
response = self.post_bom(
|
||||
'test.csv',
|
||||
bytes(dataset.csv, 'utf8'),
|
||||
content_type='text/csv',
|
||||
expected_code=400,
|
||||
)
|
||||
|
||||
self.assertIn('No data rows found', str(response.data))
|
||||
|
Loading…
Reference in New Issue
Block a user