From b4df96aaeef3c15bf99ea64524443e491564699f Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 16 May 2019 19:14:43 +1000 Subject: [PATCH] Simplify extended filters --- InvenTree/part/api.py | 16 +--------------- InvenTree/part/templates/part/category.html | 1 - InvenTree/part/test_api.py | 7 ------- InvenTree/stock/api.py | 16 +++------------- InvenTree/stock/templates/stock/location.html | 1 - 5 files changed, 4 insertions(+), 37 deletions(-) diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index e671b49e4f..0973138b21 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -12,7 +12,6 @@ from rest_framework.response import Response from rest_framework import filters from rest_framework import generics, permissions -from django.db.models import Q from django.conf.urls import url, include from django.urls import reverse @@ -109,20 +108,7 @@ class PartList(generics.ListCreateAPIView): if cat_id: try: category = PartCategory.objects.get(pk=cat_id) - - # Filter by the supplied category - flt = Q(category=cat_id) - - if self.request.query_params.get('include_child_categories', None): - childs = category.getUniqueChildren() - for child in childs: - # Ignore the top-level category (already filtered) - if str(child) == str(cat_id): - continue - flt |= Q(category=child) - - parts_list = parts_list.filter(flt) - + parts_list = parts_list.filter(category__in=category.getUniqueChildren()) except PartCategory.DoesNotExist: pass diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html index e37062beb6..fd8f20d2aa 100644 --- a/InvenTree/part/templates/part/category.html +++ b/InvenTree/part/templates/part/category.html @@ -153,7 +153,6 @@ query: { {% if category %} category: {{ category.id }}, - include_child_categories: true, {% endif %} }, buttons: ['#part-options'], diff --git a/InvenTree/part/test_api.py b/InvenTree/part/test_api.py index b8d9b7ba6d..15c6f58dcd 100644 --- a/InvenTree/part/test_api.py +++ b/InvenTree/part/test_api.py @@ -105,13 +105,6 @@ class PartAPITest(APITestCase): url = reverse('api-part-list') data = {'category': 1} - response = self.client.get(url, data, format='json') - - # There should be 1 part in this category - self.assertEqual(len(response.data), 0) - - data['include_child_categories'] = 1 - # Now request to include child categories response = self.client.get(url, data, format='json') diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index e3fbce8636..29b151ddbf 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -18,7 +18,6 @@ from .serializers import LocationSerializer from .serializers import StockTrackingSerializer from InvenTree.views import TreeSerializer -from InvenTree.helpers import str2bool from rest_framework.serializers import ValidationError from rest_framework.views import APIView @@ -249,7 +248,6 @@ class StockList(generics.ListCreateAPIView): """ If the query includes a particular location, we may wish to also request stock items from all child locations. - This is set by the optional param 'include_child_categories' """ # Does the client wish to filter by stock location? @@ -261,12 +259,8 @@ class StockList(generics.ListCreateAPIView): if loc_id: try: location = StockLocation.objects.get(pk=loc_id) - - if str2bool(self.request.query_params.get('include_child_locations', None)): - stock_list = stock_list.filter(location__in=location.getUniqueChildren()) - else: - stock_list = stock_list.filter(location=location.id) - + stock_list = stock_list.filter(location__in=location.getUniqueChildren()) + except StockLocation.DoesNotExist: pass @@ -276,11 +270,7 @@ class StockList(generics.ListCreateAPIView): if cat_id: try: category = PartCategory.objects.get(pk=cat_id) - - if str2bool(self.request.query_params.get('include_child_categories', None)): - stock_list = stock_list.filter(part__category__in=category.getUniqueChildren()) - else: - stock_list = stock_list.filter(category=category.id) + stock_list = stock_list.filter(part__category__in=category.getUniqueChildren()) except PartCategory.DoesNotExist: pass diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index c6857d9b9f..9ea210a04e 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -196,7 +196,6 @@ params: { {% if location %} location: {{ location.id }}, - include_child_locations: true, {% endif %} }, url: "{% url 'api-stock-list' %}",