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 %}
diff --git a/InvenTree/part/templates/part/category_parts.html b/InvenTree/part/templates/part/category_parts.html index b6b5a8578d..6b5321e476 100644 --- a/InvenTree/part/templates/part/category_parts.html +++ b/InvenTree/part/templates/part/category_parts.html @@ -1,5 +1,3 @@ -{% if parts|length > 0 %} -Parts: @@ -11,5 +9,4 @@ Parts: {% endfor %} -
Part{{ part.description }}
-{% endif %} \ No newline at end of file + \ No newline at end of file diff --git a/InvenTree/part/templates/part/category_subcategories.html b/InvenTree/part/templates/part/category_subcategories.html index b6bd9ee6e4..6b7f6e56a2 100644 --- a/InvenTree/part/templates/part/category_subcategories.html +++ b/InvenTree/part/templates/part/category_subcategories.html @@ -1,5 +1,3 @@ -{% if children|length > 0 %} -Subcategories: -{% endif %} \ No newline at end of file + \ No newline at end of file diff --git a/InvenTree/part/templates/part/index.html b/InvenTree/part/templates/part/index.html index 6d7496e679..dc00191271 100644 --- a/InvenTree/part/templates/part/index.html +++ b/InvenTree/part/templates/part/index.html @@ -5,9 +5,15 @@ {% include "part/cat_link.html" with category=category %} +{% if children.all|length > 0 %} +

Part Categories

{% include "part/category_subcategories.html" with children=children %} +{% endif %} +{% if parts.all|length > 0%} +

Top Level Parts

{% include "part/category_parts.html" with parts=parts %} +{% endif %}
diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index cb86e76ff0..b48514976b 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -26,8 +26,11 @@ class StockLocation(InvenTreeTree): @property def items(self): - stock_list = self.stockitem_set.all() - return stock_list + return self.stockitem_set.all() + + @property + def has_items(self): + return self.items.count() > 0 @receiver(pre_delete, sender=StockLocation, dispatch_uid='stocklocation_delete_log') @@ -60,7 +63,6 @@ class StockItem(models.Model): def get_absolute_url(self): return '/stock/item/{id}/'.format(id=self.id) - class Meta: unique_together = [ ('part', 'serial'), @@ -138,7 +140,7 @@ class StockItem(models.Model): @property def has_tracking_info(self): - return self.tracking_info.all().count() > 0 + return self.tracking_info.count() > 0 @transaction.atomic def stocktake(self, count, user): diff --git a/InvenTree/stock/templates/stock/index.html b/InvenTree/stock/templates/stock/index.html index 9d89718bb1..6af13b6744 100644 --- a/InvenTree/stock/templates/stock/index.html +++ b/InvenTree/stock/templates/stock/index.html @@ -5,6 +5,7 @@ {% include "stock/loc_link.html" with location=None %} {% if locations.all|length > 0 %} +

Storage Locations

{% include "stock/location_list.html" with locations=locations %} {% endif %} diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index f68f8cb6b0..3367848306 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -4,15 +4,18 @@ {% include "stock/loc_link.html" with location=location %} -

- {{ location.name }}
- {{ location.description }} -

- +

{{ location.name }}

+

{{ location.description }}

+{% if location.has_children %} +

Sub Locations

{% include "stock/location_list.html" with locations=location.children %} +{% endif %} +{% if location.has_items %} +

Stock Items

{% include "stock/stock_table.html" with items=location.items %} +{% endif %}
diff --git a/InvenTree/stock/templates/stock/location_list.html b/InvenTree/stock/templates/stock/location_list.html index d4804bffdb..348ef61454 100644 --- a/InvenTree/stock/templates/stock/location_list.html +++ b/InvenTree/stock/templates/stock/location_list.html @@ -1,4 +1,3 @@ -Storage locations:
    {% for child in locations.all %}
  • {{ child.name }}
  • diff --git a/InvenTree/supplier/models.py b/InvenTree/supplier/models.py index a9cf3f5453..43fed682d7 100644 --- a/InvenTree/supplier/models.py +++ b/InvenTree/supplier/models.py @@ -14,6 +14,14 @@ class Supplier(Company): def get_absolute_url(self): return "/supplier/{id}/".format(id=self.id) + @property + def part_count(self): + return self.parts.count() + + @property + def has_parts(self): + return self.part_count > 0 + class Manufacturer(Company): """ Represents a manfufacturer diff --git a/InvenTree/supplier/templates/supplier/delete.html b/InvenTree/supplier/templates/supplier/delete.html index 1e3d63fec7..d42b93f864 100644 --- a/InvenTree/supplier/templates/supplier/delete.html +++ b/InvenTree/supplier/templates/supplier/delete.html @@ -5,12 +5,12 @@ Are you sure you want to delete supplier '{{ supplier.name }}'? {% endblock %} {% block del_body %} -{% if supplier.parts.all|length > 0 %} -

    There are {{ supplier.parts.all|length }} parts sourced from this supplier.
    -If this supplier is deleted, these child categories will also be deleted.

    +{% if supplier.part_count > 0 %} +

    There are {{ supplier.part_count }} parts sourced from this supplier.
    +If this supplier is deleted, these supplier part entries will also be deleted.

      {% for part in supplier.parts.all %} -
    • {{ part.SKU }}Part - {{ part.part.name }}
    • +
    • {{ part.SKU }}
      Part - {{ part.part.name }}
    • {% endfor %}
    {% endif %}