From 67eda51cd20142fe4ec005b0c7f3cd06ced500b0 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 4 May 2019 21:56:18 +1000 Subject: [PATCH] Add part category tree traversal - If a category doesn't have a default_location, look at the parent category - And so on and so on --- InvenTree/part/models.py | 10 +++++++++- InvenTree/part/templates/part/category.html | 5 ++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index f3caeeae6a..cdd9247b13 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -159,8 +159,16 @@ class Part(models.Model): if self.default_location: return self.default_location elif self.category: - return self.category.default_location + # Traverse up the category tree until we find a default location + cat = self.category + while cat: + if cat.default_location: + return cat.default_location + else: + cat = cat.parent + + # Default case - no default category found return None # Default supplier part diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html index d03d18be44..7dad872114 100644 --- a/InvenTree/part/templates/part/category.html +++ b/InvenTree/part/templates/part/category.html @@ -8,8 +8,11 @@ {% if category %}

{{ category.name }}

{{ category.description }}

+ {% if category.default_location %} +

Default Location: {{ category.default_location }}

+ {% endif %} {% else %} -

Parts

+

Part Categories

{% endif %}