From 18ff80312b6cd9c09974542da00e124d1f870b1e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 20 May 2019 22:53:01 +1000 Subject: [PATCH] Fixes --- InvenTree/part/models.py | 4 ++-- InvenTree/part/serializers.py | 4 +++- InvenTree/stock/serializers.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 569f373a3d..6d6f02f6a3 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -463,7 +463,7 @@ class Part(models.Model): @property def allocated_build_count(self): - """ Return the total number of this that are allocated for builds + """ Return the total number of this part that are allocated for builds """ return sum([a['quantity'] for a in self.build_allocation]) @@ -530,7 +530,7 @@ class Part(models.Model): returns a string representation of a hash object which can be compared with a stored value """ - hash = hashlib.md5(str(item.part.id).encode()) + hash = hashlib.md5(str(self.id).encode()) for item in self.bom_items.all(): hash.update(str(item.sub_part.id).encode()) diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index c847785476..e91a3c6589 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -112,6 +112,7 @@ class PartStarSerializer(InvenTreeModelSerializer): class BomItemSerializer(InvenTreeModelSerializer): """ Serializer for BomItem object """ + part_detail = PartBriefSerializer(source='part', many=False, read_only=True) sub_part_detail = PartBriefSerializer(source='sub_part', many=False, read_only=True) price_info = serializers.CharField(read_only=True) @@ -119,7 +120,7 @@ class BomItemSerializer(InvenTreeModelSerializer): def setup_eager_loading(queryset): queryset = queryset.prefetch_related('sub_part') queryset = queryset.prefetch_related('sub_part__category') - queryset = queryset.prefetch_related('sub_part__locations') + queryset = queryset.prefetch_related('sub_part__stock_items') return queryset class Meta: @@ -127,6 +128,7 @@ class BomItemSerializer(InvenTreeModelSerializer): fields = [ 'pk', 'part', + 'part_detail', 'sub_part', 'sub_part_detail', 'quantity', diff --git a/InvenTree/stock/serializers.py b/InvenTree/stock/serializers.py index 46a1c44845..40697a0aee 100644 --- a/InvenTree/stock/serializers.py +++ b/InvenTree/stock/serializers.py @@ -63,7 +63,7 @@ class StockItemSerializer(serializers.ModelSerializer): @staticmethod def setup_eager_loading(queryset): queryset = queryset.prefetch_related('part') - queryset = queryset.prefetch_related('part__locations') + queryset = queryset.prefetch_related('part__stock_items') queryset = queryset.prefetch_related('part__category') queryset = queryset.prefetch_related('location')