A little whoopsie-doo:

- Part.clean() was incorrectly referencing a BomItem when it should have been referencing BomItem.part
This commit is contained in:
Oliver Walters 2020-11-11 16:09:14 +11:00
parent 6d5bdaadbd
commit 039a7badd1

View File

@ -571,7 +571,8 @@ class Part(MPTTModel):
super().clean() super().clean()
if self.trackable: 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: if not parent_part.trackable:
parent_part.trackable = True parent_part.trackable = True
parent_part.clean() parent_part.clean()
@ -1041,8 +1042,16 @@ class Part(MPTTModel):
- Exclude parts which this part is in the BOM for - Exclude parts which this part is in the BOM for
""" """
parts = Part.objects.filter(component=True).exclude(id=self.id) # Start with a list of all parts designated as 'sub components'
parts = parts.exclude(id__in=[part.id for part in self.used_in.all()]) 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 return parts