From 937470750b11399a70fe4d3a2b9b1b3a1d747e57 Mon Sep 17 00:00:00 2001
From: Oliver
Date: Mon, 16 Apr 2018 23:26:02 +1000
Subject: [PATCH] Added helper functions, improved UI
---
InvenTree/InvenTree/models.py | 4 ++++
InvenTree/part/models.py | 12 +++++-------
InvenTree/part/templates/part/category_detail.html | 6 ++++++
InvenTree/part/templates/part/category_parts.html | 5 +----
.../part/templates/part/category_subcategories.html | 5 +----
InvenTree/part/templates/part/index.html | 6 ++++++
InvenTree/stock/models.py | 10 ++++++----
InvenTree/stock/templates/stock/index.html | 1 +
InvenTree/stock/templates/stock/location.html | 13 ++++++++-----
InvenTree/stock/templates/stock/location_list.html | 1 -
InvenTree/supplier/models.py | 8 ++++++++
InvenTree/supplier/templates/supplier/delete.html | 8 ++++----
12 files changed, 50 insertions(+), 29 deletions(-)
diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py
index fc39cf9233..06bf758b84 100644
--- a/InvenTree/InvenTree/models.py
+++ b/InvenTree/InvenTree/models.py
@@ -90,6 +90,10 @@ class InvenTreeTree(models.Model):
return unique
+ @property
+ def has_children(self):
+ return self.children.count() > 0
+
@property
def children(self):
contents = ContentType.objects.get_for_model(type(self))
diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py
index 3edd260f9b..3d2fe90628 100644
--- a/InvenTree/part/models.py
+++ b/InvenTree/part/models.py
@@ -35,11 +35,9 @@ class PartCategory(InvenTreeTree):
return count
- """
@property
- def parts(self):
- return self.part_set.all()
- """
+ def has_parts(self):
+ return self.parts.count() > 0
@receiver(pre_delete, sender=PartCategory, dispatch_uid='partcategory_delete_log')
@@ -186,16 +184,16 @@ class Part(models.Model):
@property
def bom_count(self):
- return self.bom_items.all().count()
+ return self.bom_items.count()
@property
def used_in_count(self):
- return self.used_in.all().count()
+ return self.used_in.count()
@property
def supplier_count(self):
# Return the number of supplier parts available for this part
- return self.supplier_parts.all().count()
+ return self.supplier_parts.count()
"""
@property
diff --git a/InvenTree/part/templates/part/category_detail.html b/InvenTree/part/templates/part/category_detail.html
index ed9fc8f996..7e91c82a59 100644
--- a/InvenTree/part/templates/part/category_detail.html
+++ b/InvenTree/part/templates/part/category_detail.html
@@ -11,9 +11,15 @@
{{ category.description }}
+{% if category.has_children %}
+Subcategories
{% include "part/category_subcategories.html" with children=category.children.all %}
+{% endif %}
+{% if category.has_parts %}
+Parts
{% include "part/category_parts.html" with parts=category.parts.all %}
+{% endif %}