From fd3f6ec21e79c9808221537645cd0aa8f5ebd31b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 18 Apr 2019 08:33:12 +1000 Subject: [PATCH 1/7] Add stock item filtering by sub-category --- InvenTree/part/api.py | 3 +- InvenTree/stock/api.py | 34 +++++++++++++++++-- InvenTree/stock/templates/stock/location.html | 3 +- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index e13d493fc3..5601850e1c 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -87,13 +87,12 @@ class PartList(generics.ListCreateAPIView): childs = category.getUniqueChildren() for child in childs: # Ignore the top-level category (already filtered) - if child == cat_id: + if str(child) == str(cat_id): continue flt |= Q(category=child) parts_list = parts_list.filter(flt) - # Default - return all parts return parts_list permission_classes = [ diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index e8ab68acfe..32e3807ef7 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -2,6 +2,8 @@ from django_filters.rest_framework import FilterSet, DjangoFilterBackend from django_filters import NumberFilter from django.conf.urls import url, include +from django.db.models import Q +from django.shortcuts import get_object_or_404 from .models import StockLocation, StockItem from .models import StockItemTracking @@ -202,7 +204,36 @@ class StockList(generics.ListCreateAPIView): Create a new StockItem """ - queryset = StockItem.objects.all() + def get_queryset(self): + """ + 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 category? + loc_id = self.request.query_params.get('location', None) + + # Start with all objects + stock_list = StockItem.objects.all() + + if loc_id: + location = get_object_or_404(StockLocation, pk=loc_id) + + # Filter by the supplied category + flt = Q(location=loc_id) + + if self.request.query_params.get('include_child_locations', None): + childs = location.getUniqueChildren() + for child in childs: + # Ignore the top-level category (already filtered!) + if str(child) == str(loc_id): + continue + flt |= Q(location=child) + + stock_list = stock_list.filter(flt) + + return stock_list serializer_class = StockItemSerializer @@ -219,7 +250,6 @@ class StockList(generics.ListCreateAPIView): filter_fields = [ 'part', 'uuid', - 'location', 'supplier_part', 'customer', 'belongs_to', diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 79ae9ecd15..79a93ccda1 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -160,7 +160,8 @@ loadStockTable($("#stock-table"), { params: { {% if location %} - location: {{ location.id }} + location: {{ location.id }}, + include_child_locations: true, {% endif %} }, url: "{% url 'api-stock-list' %}", From 18c48e9191df61414d2240a250d6ddbb88e2423b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 18 Apr 2019 08:33:25 +1000 Subject: [PATCH 2/7] Split part details display into two columns --- InvenTree/part/templates/part/detail.html | 144 ++++++++++++---------- 1 file changed, 76 insertions(+), 68 deletions(-) diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index b340ec35c5..7524874a28 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -25,74 +25,82 @@
- - - - - - - - - -{% if part.IPN %} - - - - -{% endif %} - - - - -{% if part.default_location %} - - - - -{% endif %} -{% if part.default_supplier %} - - - - -{% endif %} - - - - - - - - - - - - - - - - - - - - - - - - -{% if part.minimum_stock > 0 %} - - - - -{% endif %} -
Part name{{ part.name }}
Description{{ part.description }}
IPN{{ part.IPN }}
Category - {% if part.category %} - {{ part.category.pathstring }} - {% endif %} -
Default Location{{ part.default_location.pathstring }}
Default Supplier - {{ part.default_supplier.supplier.name }} | {{ part.default_supplier.SKU }} -
Units{{ part.units }}
Buildable{% include "yesnolabel.html" with value=part.buildable %}
Consumable{% include "yesnolabel.html" with value=part.consumable %}
Trackable{% include "yesnolabel.html" with value=part.trackable %}
Purchaseable{% include "yesnolabel.html" with value=part.purchaseable %}
Salable{% include "yesnolabel.html" with value=part.salable %}
Minimum Stock{{ part.minimum_stock }}
+
+
+ + + + + + + + + + {% if part.IPN %} + + + + + {% endif %} + + + + + {% if part.default_location %} + + + + + {% endif %} + {% if part.default_supplier %} + + + + + {% endif %} + + + + +
Part name{{ part.name }}
Description{{ part.description }}
IPN{{ part.IPN }}
Category + {% if part.category %} + {{ part.category.pathstring }} + {% endif %} +
Default Location{{ part.default_location.pathstring }}
Default Supplier + {{ part.default_supplier.supplier.name }} | {{ part.default_supplier.SKU }} +
Units{{ part.units }}
+
+
+ + + + + + + + + + + + + + + + + + + + + + {% if part.minimum_stock > 0 %} + + + + + {% endif %} +
Buildable{% include "yesnolabel.html" with value=part.buildable %}
Consumable{% include "yesnolabel.html" with value=part.consumable %}
Trackable{% include "yesnolabel.html" with value=part.trackable %}
Purchaseable{% include "yesnolabel.html" with value=part.purchaseable %}
Salable{% include "yesnolabel.html" with value=part.salable %}
Minimum Stock{{ part.minimum_stock }}
+
+
{% if part.notes %}
From 8dc3063765656bfa43a43bc7ac3ecaf961205b98 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 18 Apr 2019 08:40:16 +1000 Subject: [PATCH 3/7] Vertical centering for header image --- InvenTree/templates/navbar.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/templates/navbar.html b/InvenTree/templates/navbar.html index 64bb7ec34c..005e342bf3 100644 --- a/InvenTree/templates/navbar.html +++ b/InvenTree/templates/navbar.html @@ -3,7 +3,7 @@