From a9f255be853fcc355a061db6e52b4483eff9607c Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 18 Feb 2021 18:01:41 +1100 Subject: [PATCH] Prevent stock item being added as an installed item inside itself --- InvenTree/stock/models.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 5d7cce5132..2cfaf2ce68 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -714,18 +714,23 @@ class StockItem(MPTTModel): items = StockItem.objects.filter(belongs_to=self) for item in items: + + # Prevent duplication or recursion + if item == self or item in installed: + continue - # Prevent recursion - if item not in installed: - installed.add(item) + installed.add(item) if cascade: sub_items = item.get_installed_items(cascade=True) for sub_item in sub_items: + # Prevent recursion - if sub_item not in installed: - installed.add(sub_item) + if sub_item == self or sub_item in installed: + continue + + installed.add(sub_item) return installed