diff --git a/InvenTree/order/test_api.py b/InvenTree/order/test_api.py index 04be484310..f06e26370d 100644 --- a/InvenTree/order/test_api.py +++ b/InvenTree/order/test_api.py @@ -989,7 +989,7 @@ class SalesOrderDownloadTest(OrderTest): }, expected_code=200, expected_fn='InvenTree_SalesOrders.xls', - deode=False, + decode=False, ) as fo: self.assertTrue(isinstance(fo, io.BytesIO)) diff --git a/InvenTree/part/admin.py b/InvenTree/part/admin.py index 8021bd10fa..5fafc37fea 100644 --- a/InvenTree/part/admin.py +++ b/InvenTree/part/admin.py @@ -45,6 +45,7 @@ class PartResource(ModelResource): exclude = [ 'bom_checksum', 'bom_checked_by', 'bom_checked_date', 'lft', 'rght', 'tree_id', 'level', + 'metadata', ] def get_queryset(self): @@ -98,6 +99,7 @@ class PartCategoryResource(ModelResource): exclude = [ # Exclude MPTT internal model fields 'lft', 'rght', 'tree_id', 'level', + 'metadata', ] def after_import(self, dataset, result, using_transactions, dry_run, **kwargs): diff --git a/InvenTree/part/test_api.py b/InvenTree/part/test_api.py index 28df4503c9..46b7a477f8 100644 --- a/InvenTree/part/test_api.py +++ b/InvenTree/part/test_api.py @@ -822,6 +822,58 @@ class PartAPITest(InvenTreeAPITestCase): response = self.get('/api/part/10004/', {}) self.assertEqual(response.data['variant_stock'], 500) + def test_part_download(self): + """Test download of part data via the API""" + + url = reverse('api-part-list') + + required_cols = [ + 'id', + 'name', + 'description', + 'in_stock', + 'category_name', + 'keywords', + 'is_template', + 'virtual', + 'trackable', + 'active', + 'notes', + 'creation_date', + ] + + excluded_cols = [ + 'lft', 'rght', 'level', 'tree_id', + 'metadata', + ] + + with self.download_file( + url, + { + 'export': 'csv', + }, + expected_fn='InvenTree_Parts.csv', + ) as fo: + + data = self.process_csv( + fo, + excluded_cols=excluded_cols, + required_cols=required_cols, + required_rows=Part.objects.count(), + ) + + for row in data: + part = Part.objects.get(pk=row['id']) + + if part.IPN: + self.assertEqual(part.IPN, row['IPN']) + + self.assertEqual(part.name, row['name']) + self.assertEqual(part.description, row['description']) + + if part.category: + self.assertEqual(part.category.name, row['category_name']) + class PartDetailTests(InvenTreeAPITestCase): """