From 039a7badd1be6c3f0a68dc46f80d32fbde541b4e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 11 Nov 2020 16:09:14 +1100 Subject: [PATCH] A little whoopsie-doo: - Part.clean() was incorrectly referencing a BomItem when it should have been referencing BomItem.part --- InvenTree/part/models.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index d6c536db59..1f1c06e81e 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -571,7 +571,8 @@ class Part(MPTTModel): super().clean() if self.trackable: - for parent_part in self.used_in.all(): + for item in self.used_in.all(): + parent_part = item.part if not parent_part.trackable: parent_part.trackable = True parent_part.clean() @@ -1041,8 +1042,16 @@ class Part(MPTTModel): - Exclude parts which this part is in the BOM for """ - parts = Part.objects.filter(component=True).exclude(id=self.id) - parts = parts.exclude(id__in=[part.id for part in self.used_in.all()]) + # Start with a list of all parts designated as 'sub components' + parts = Part.objects.filter(component=True) + + # Exclude this part + parts = parts.exclude(id=self.id) + + # Exclude any parts that this part is used *in* (to prevent recursive BOMs) + used_in = self.used_in.all() + + parts = parts.exclude(id__in=[item.part.id for item in used_in]) return parts