2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-13 08:21:26 +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:
Oliver Walters
2019-05-04 21:56:18 +10:00
parent 71972f4454
commit 67eda51cd2
2 changed files with 13 additions and 2 deletions

View File

@ -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