From a5189b8f3fd4ec2842fc561ccc936ce0b0b4af6d Mon Sep 17 00:00:00 2001
From: Oliver Walters <oliver.henry.walters@gmail.com>
Date: Sun, 8 Sep 2019 19:28:40 +1000
Subject: [PATCH] Replace a recursive function

---
 InvenTree/part/models.py | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py
index e9cae5142b..73cfa96e2c 100644
--- a/InvenTree/part/models.py
+++ b/InvenTree/part/models.py
@@ -382,13 +382,11 @@ class Part(models.Model):
             return self.default_location
         elif self.category:
             # Traverse up the category tree until we find a default location
-            cat = self.category
+            cats = self.category.get_ancestors(ascending=True, include_self=True)
 
-            while cat:
-                if cat.default_location:
+            for cat in cats:
+                if cat.defaul_location:
                     return cat.default_location
-                else:
-                    cat = cat.parent
 
         # Default case - no default category found
         return None