Logic fix for build calculation (#4161)

- Fixes logic for "required_parts_to_complete_build" method
This commit is contained in:
Oliver 2023-01-07 01:04:57 +11:00 committed by GitHub
parent 34bb40d439
commit 09e02755ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1072,12 +1072,15 @@ class Build(MPTTModel, ReferenceIndexingMixin):
@property
def required_parts_to_complete_build(self):
"""Returns a list of parts required to complete the full build."""
"""Returns a list of parts required to complete the full build.
TODO: 2022-01-06 : This method needs to be improved, it is very inefficient in terms of DB hits!
"""
parts = []
for bom_item in self.bom_items:
# Get remaining quantity needed
required_quantity_to_complete_build = self.remaining * bom_item.quantity
required_quantity_to_complete_build = self.remaining * bom_item.quantity - self.allocated_quantity(bom_item)
# Compare to net stock
if bom_item.sub_part.net_stock < required_quantity_to_complete_build:
parts.append(bom_item.sub_part)