From 6ebce2b2fde8795c13b1f9aab9eeb9401c8b58e9 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 5 Jun 2020 12:06:28 +1000 Subject: [PATCH] Add ability to filter purchase orders by "outstanding" status --- InvenTree/order/api.py | 12 ++++++++++++ InvenTree/templates/js/table_filters.html | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/InvenTree/order/api.py b/InvenTree/order/api.py index dba493baab..0c1ef8b3ae 100644 --- a/InvenTree/order/api.py +++ b/InvenTree/order/api.py @@ -13,6 +13,7 @@ from django.conf.urls import url, include from InvenTree.helpers import str2bool from InvenTree.api import AttachmentMixin +from InvenTree.status_codes import PurchaseOrderStatus from part.models import Part from company.models import SupplierPart @@ -68,6 +69,17 @@ class POList(generics.ListCreateAPIView): params = self.request.query_params + # Filter by 'outstanding' status + outstanding = params.get('outstanding', None) + + if outstanding is not None: + outstanding = str2bool(outstanding) + + if outstanding: + queryset = queryset.filter(status__in=PurchaseOrderStatus.OPEN) + else: + queryset = queryset.exclude(status__in=PurchaseOrderStatus.OPEN) + # Special filtering for 'status' field status = params.get('status', None) diff --git a/InvenTree/templates/js/table_filters.html b/InvenTree/templates/js/table_filters.html index 298a034517..285abb36f9 100644 --- a/InvenTree/templates/js/table_filters.html +++ b/InvenTree/templates/js/table_filters.html @@ -78,11 +78,16 @@ function getAvailableTableFilters(tableKey) { // Filters for the "Order" table if (tableKey == "purchaseorder") { + return { status: { title: '{% trans "Order status" %}', options: purchaseOrderCodes, }, + outstanding: { + type: 'bool', + title: '{% trans "Outstanding" %}', + }, }; }