2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 20:45:44 +00:00

More hungry fetching

This commit is contained in:
Oliver Walters
2019-05-21 00:16:00 +10:00
parent 157919f47a
commit 72aba30e81
3 changed files with 7 additions and 4 deletions

View File

@ -139,7 +139,7 @@ class Build(models.Model):
allocations = []
for item in self.part.bom_items.all():
for item in self.part.bom_items.all().prefetch_related('sub_part'):
# How many parts required for this build?
q_required = item.quantity * self.quantity
@ -216,7 +216,7 @@ class Build(models.Model):
- Delete pending BuildItem objects
"""
for item in self.allocated_stock.all():
for item in self.allocated_stock.all().prefetch_related('stock_item'):
# Subtract stock from the item
item.stock_item.take_stock(
@ -295,7 +295,7 @@ class Build(models.Model):
""" Returns a dict of parts required to build this part (BOM) """
parts = []
for item in self.part.bom_items.all():
for item in self.part.bom_items.all().prefetch_related('sub_part'):
part = {'part': item.sub_part,
'per_build': item.quantity,
'quantity': item.quantity * self.quantity,