From 8723a6c21954c3894f79815d6215748f7cd35d26 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 9 Sep 2019 19:10:57 +1000 Subject: [PATCH 1/4] Add 'purchaseable' field to part export --- InvenTree/part/views.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index dc2697ee39..2edcd65075 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -1187,6 +1187,7 @@ class PartExport(AjaxView): 'Component', 'Template', 'Trackable', + 'Purchaseable', 'Salable', 'Active', 'Virtual', @@ -1233,6 +1234,7 @@ class PartExport(AjaxView): line.append(part.component) line.append(part.is_template) line.append(part.trackable) + line.append(part.purchaseable) line.append(part.salable) line.append(part.active) line.append(part.virtual) From 776fc8b1e55d02bebee6c26a98ec74ec3260166f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 9 Sep 2019 19:37:59 +1000 Subject: [PATCH 2/4] Add 'used_in' count to part export --- InvenTree/part/views.py | 73 +++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 2edcd65075..7959e2b6a6 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -1162,15 +1162,53 @@ class BomUpload(FormView): class PartExport(AjaxView): """ Export a CSV file containing information on multiple parts """ - def get(self, request, *args, **kwargs): - part = request.GET.get('parts', '') - parts = [] + def get_parts(self, request): + """ Extract part list from the POST parameters. + Parts can be supplied as: - for pk in part.split(','): + - List of part PK values + - Part category + """ + + part_list = Part.objects.all() + + part_ids = request.GET.get('parts', '') + parts = [] + + for pk in part_ids.split(','): try: - parts.append(Part.objects.get(pk=int(pk))) - except (Part.DoesNotExist, ValueError): - continue + parts.append(int(pk)) + except ValueError: + pass + + # Filter by list of Part IDs + if len(parts) > 0: + part_list = part_list.filter(pk__in=parts) + + # Filter by part category + cat_id = request.GET.get('category', None) + + if cat_id is not None: + try: + category = PartCategory.objects.get(cat_id) + part_list = part_list.filter(category=category) + except (ValueError, PartCategory.DoesNotExist): + pass + + # Prefetch related fields to reduce DB hits + part_list = part_list.prefetch_related( + 'category', + 'used_in', + 'builds', + 'supplier_parts__purchase_order_line_items', + 'stock_items__allocations', + ) + + return part_list + + def get(self, request, *args, **kwargs): + + parts = self.get_parts(request) headers = [ 'ID', @@ -1191,7 +1229,12 @@ class PartExport(AjaxView): 'Salable', 'Active', 'Virtual', - 'Stock Info', # Spacer between part data and stock data + + # Part meta-data + 'Used In', + + # Stock Information + 'Stock Info', 'In Stock', 'Allocated', 'Building', @@ -1223,8 +1266,14 @@ class PartExport(AjaxView): line.append(part.pk) line.append(part.name) line.append(part.description) - line.append(str(part.category)) - line.append(part.category.pk) + + if part.category: + line.append(str(part.category)) + line.append(part.category.pk) + else: + line.append('') + line.append('') + line.append(part.IPN) line.append(part.revision) line.append(part.URL) @@ -1239,6 +1288,9 @@ class PartExport(AjaxView): line.append(part.active) line.append(part.virtual) + # Part meta-data + line.append(part.used_in_count) + # Stock information line.append('') line.append(part.total_stock) @@ -1246,6 +1298,7 @@ class PartExport(AjaxView): line.append(part.quantity_being_built) line.append(part.on_order) + # Supplier Information if len(supplier_names) > 0: line.append('') From ddb041fe44800cc4a5de49cea18669e75c8169dc Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 9 Sep 2019 19:59:56 +1000 Subject: [PATCH 3/4] Filter by category too --- InvenTree/part/templates/part/category.html | 8 ++++++ InvenTree/part/views.py | 32 ++++++++++++--------- InvenTree/templates/stock_table.html | 2 +- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html index 6a076ef8ca..26098be946 100644 --- a/InvenTree/part/templates/part/category.html +++ b/InvenTree/part/templates/part/category.html @@ -44,6 +44,7 @@
+