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 %} +Part | @@ -11,5 +9,4 @@ Parts:{{ part.description }} |
---|
- {{ location.name }}
- {{ location.description }}
-
{{ location.description }}
+{% if location.has_children %} +There are {{ supplier.parts.all|length }} parts sourced from this supplier.
-If this supplier is deleted, these child categories will also be deleted.
There are {{ supplier.part_count }} parts sourced from this supplier.
+If this supplier is deleted, these supplier part entries will also be deleted.