From 37dba91b4a8fd420946f7a65533c83d1aa5162f6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 18 Jun 2019 01:02:56 +1000 Subject: [PATCH] Add 'include self' option to getUniqueChildren --- InvenTree/InvenTree/models.py | 5 ++++- InvenTree/part/api.py | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py index eeee6378c6..e95b763c05 100644 --- a/InvenTree/InvenTree/models.py +++ b/InvenTree/InvenTree/models.py @@ -80,7 +80,7 @@ class InvenTreeTree(models.Model): return unique - def getUniqueChildren(self, unique=None): + def getUniqueChildren(self, unique=None, include_self=False): """ Return a flat set of all child items that exist under this node. If any child items are repeated, the repetitions are omitted. """ @@ -88,6 +88,9 @@ class InvenTreeTree(models.Model): if unique is None: unique = set() + if include_self: + unique.add(self.id) + if self.id in unique: return unique diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index bf0555a216..64b08f06b5 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -110,8 +110,7 @@ class PartList(generics.ListCreateAPIView): if cat_id: try: category = PartCategory.objects.get(pk=cat_id) - cats = [category.id] - cats += [cat for cat in category.getUniqueChildren()] + cats = category.getUniqueChildren(include_self=True) parts_list = parts_list.filter(category__in=cats) except PartCategory.DoesNotExist: pass