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:
@ -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
|
||||
|
Reference in New Issue
Block a user