From 298e9cae65168a9f8f28e6ccd2961918016fbcc2 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 3 Jan 2021 10:07:38 +1100 Subject: [PATCH 1/5] Fix variable scope issue --- InvenTree/part/forms.py | 4 +++- InvenTree/part/models.py | 7 +++++-- InvenTree/part/templates/part/bom.html | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/InvenTree/part/forms.py b/InvenTree/part/forms.py index 68912edd98..1cbbec0b42 100644 --- a/InvenTree/part/forms.py +++ b/InvenTree/part/forms.py @@ -319,7 +319,9 @@ class EditBomItemForm(HelperForm): ] # Prevent editing of the part associated with this BomItem - widgets = {'part': forms.HiddenInput()} + widgets = { + 'part': forms.HiddenInput() + } class PartPriceForm(forms.Form): diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index cf0c92899a..b9d63979e7 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -1074,7 +1074,7 @@ class Part(MPTTModel): self.bom_items.all().delete() - def getRequiredParts(self, recursive=False, parts=set()): + def getRequiredParts(self, recursive=False, parts=None): """ Return a list of parts required to make this part (i.e. BOM items). @@ -1083,7 +1083,10 @@ class Part(MPTTModel): parts: Set of parts already found (to prevent recursion issues) """ - items = self.bom_items.all().prefetch_related('sub_part') + if parts is None: + parts = set() + + items = BomItem.objects.filter(part=self.pk) for bom_item in items: diff --git a/InvenTree/part/templates/part/bom.html b/InvenTree/part/templates/part/bom.html index 38d07cb00e..0b24582220 100644 --- a/InvenTree/part/templates/part/bom.html +++ b/InvenTree/part/templates/part/bom.html @@ -32,7 +32,7 @@
{% if editing_enabled %}