2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-19 21:45:39 +00:00

Merge branch 'inventree:master' into fr-1421-sso

This commit is contained in:
Matthias Mair
2021-10-08 22:38:16 +02:00
committed by GitHub
5 changed files with 72 additions and 23 deletions

View File

@ -1100,6 +1100,12 @@ class BomList(generics.ListCreateAPIView):
except AttributeError:
pass
try:
# Include or exclude pricing information in the serialized data
kwargs['include_pricing'] = str2bool(self.request.GET.get('include_pricing', True))
except AttributeError:
pass
# Ensure the request context is passed through!
kwargs['context'] = self.get_serializer_context()
@ -1141,6 +1147,18 @@ class BomList(generics.ListCreateAPIView):
except (ValueError, Part.DoesNotExist):
pass
include_pricing = str2bool(params.get('include_pricing', True))
if include_pricing:
queryset = self.annotate_pricing(queryset)
return queryset
def annotate_pricing(self, queryset):
"""
Add part pricing information to the queryset
"""
# Annotate with purchase prices
queryset = queryset.annotate(
purchase_price_min=Min('sub_part__stock_items__purchase_price'),

View File

@ -419,6 +419,7 @@ class BomItemSerializer(InvenTreeModelSerializer):
part_detail = kwargs.pop('part_detail', False)
sub_part_detail = kwargs.pop('sub_part_detail', False)
include_pricing = kwargs.pop('include_pricing', False)
super(BomItemSerializer, self).__init__(*args, **kwargs)
@ -428,6 +429,14 @@ class BomItemSerializer(InvenTreeModelSerializer):
if sub_part_detail is not True:
self.fields.pop('sub_part_detail')
if not include_pricing:
# Remove all pricing related fields
self.fields.pop('price_range')
self.fields.pop('purchase_price_min')
self.fields.pop('purchase_price_max')
self.fields.pop('purchase_price_avg')
self.fields.pop('purchase_price_range')
@staticmethod
def setup_eager_loading(queryset):
queryset = queryset.prefetch_related('part')