mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
More hungry fetching
This commit is contained in:
parent
157919f47a
commit
72aba30e81
@ -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,
|
||||
|
@ -532,7 +532,7 @@ class Part(models.Model):
|
||||
|
||||
hash = hashlib.md5(str(self.id).encode())
|
||||
|
||||
for item in self.bom_items.all().prefetch('sub_part'):
|
||||
for item in self.bom_items.all().prefetch_related('sub_part'):
|
||||
hash.update(str(item.sub_part.id).encode())
|
||||
hash.update(str(item.sub_part.full_name).encode())
|
||||
hash.update(str(item.quantity).encode())
|
||||
|
@ -125,6 +125,9 @@ class BomItemSerializer(InvenTreeModelSerializer):
|
||||
|
||||
@staticmethod
|
||||
def setup_eager_loading(queryset):
|
||||
queryset = queryset.prefetch_related('part')
|
||||
queryset = queryset.prefetch_related('part__category')
|
||||
queryset = queryset.prefetch_related('part__stock_items')
|
||||
queryset = queryset.prefetch_related('sub_part')
|
||||
queryset = queryset.prefetch_related('sub_part__category')
|
||||
queryset = queryset.prefetch_related('sub_part__stock_items')
|
||||
|
Loading…
Reference in New Issue
Block a user