This commit is contained in:
Oliver Walters 2019-05-20 22:53:01 +10:00
parent 4bde00d925
commit 18ff80312b
3 changed files with 6 additions and 4 deletions

View File

@ -463,7 +463,7 @@ class Part(models.Model):
@property @property
def allocated_build_count(self): 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]) 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 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(): for item in self.bom_items.all():
hash.update(str(item.sub_part.id).encode()) hash.update(str(item.sub_part.id).encode())

View File

@ -112,6 +112,7 @@ class PartStarSerializer(InvenTreeModelSerializer):
class BomItemSerializer(InvenTreeModelSerializer): class BomItemSerializer(InvenTreeModelSerializer):
""" Serializer for BomItem object """ """ 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) sub_part_detail = PartBriefSerializer(source='sub_part', many=False, read_only=True)
price_info = serializers.CharField(read_only=True) price_info = serializers.CharField(read_only=True)
@ -119,7 +120,7 @@ class BomItemSerializer(InvenTreeModelSerializer):
def setup_eager_loading(queryset): def setup_eager_loading(queryset):
queryset = queryset.prefetch_related('sub_part') queryset = queryset.prefetch_related('sub_part')
queryset = queryset.prefetch_related('sub_part__category') queryset = queryset.prefetch_related('sub_part__category')
queryset = queryset.prefetch_related('sub_part__locations') queryset = queryset.prefetch_related('sub_part__stock_items')
return queryset return queryset
class Meta: class Meta:
@ -127,6 +128,7 @@ class BomItemSerializer(InvenTreeModelSerializer):
fields = [ fields = [
'pk', 'pk',
'part', 'part',
'part_detail',
'sub_part', 'sub_part',
'sub_part_detail', 'sub_part_detail',
'quantity', 'quantity',

View File

@ -63,7 +63,7 @@ class StockItemSerializer(serializers.ModelSerializer):
@staticmethod @staticmethod
def setup_eager_loading(queryset): def setup_eager_loading(queryset):
queryset = queryset.prefetch_related('part') 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('part__category')
queryset = queryset.prefetch_related('location') queryset = queryset.prefetch_related('location')