mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
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
This commit is contained in:
parent
71972f4454
commit
67eda51cd2
@ -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
|
||||
|
@ -8,8 +8,11 @@
|
||||
{% if category %}
|
||||
<h3>{{ category.name }}</h3>
|
||||
<p>{{ category.description }}</p>
|
||||
{% if category.default_location %}
|
||||
<p>Default Location: <a href="{% url 'stock-location-detail' category.default-location.id }%">{{ category.default_location }}</a></p>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<h3>Parts</h3>
|
||||
<h3>Part Categories</h3>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class='col-sm-6'>
|
||||
|
Loading…
Reference in New Issue
Block a user