mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 05:05:42 +00:00 
			
		
		
		
	Add optional detail elements to SOAllocation API
This commit is contained in:
		| @@ -435,6 +435,16 @@ class SOAllocationList(generics.ListCreateAPIView): | ||||
|     queryset = SalesOrderAllocation.objects.all() | ||||
|     serializer_class = SalesOrderAllocationSerializer | ||||
|  | ||||
|     def get_serializer(self, *args, **kwargs): | ||||
|  | ||||
|         params = self.request.query_params | ||||
|  | ||||
|         kwargs['part_detail'] = str2bool(params.get('part_detail', False)) | ||||
|         kwargs['item_detail'] = str2bool(params.get('item_detail', False)) | ||||
|         kwargs['order_detail'] = str2bool(params.get('order_detail', False)) | ||||
|  | ||||
|         return self.serializer_class(*args, **kwargs) | ||||
|  | ||||
|     def filter_queryset(self, queryset): | ||||
|  | ||||
|         queryset = super().filter_queryset(queryset) | ||||
|   | ||||
| @@ -17,6 +17,7 @@ from InvenTree.serializers import InvenTreeAttachmentSerializerField | ||||
|  | ||||
| from company.serializers import CompanyBriefSerializer, SupplierPartSerializer | ||||
| from part.serializers import PartBriefSerializer | ||||
| from stock.serializers import StockItemSerializer | ||||
|  | ||||
| from .models import PurchaseOrder, PurchaseOrderLineItem | ||||
| from .models import PurchaseOrderAttachment, SalesOrderAttachment | ||||
| @@ -232,13 +233,33 @@ class SalesOrderAllocationSerializer(InvenTreeModelSerializer): | ||||
|     This includes some fields from the related model objects. | ||||
|     """ | ||||
|  | ||||
|     location_path = serializers.CharField(source='get_location_path', read_only=True) | ||||
|     location = serializers.IntegerField(source='get_location', read_only=True) | ||||
|     part = serializers.PrimaryKeyRelatedField(source='item.part', read_only=True) | ||||
|     order = serializers.PrimaryKeyRelatedField(source='line.order', many=False, read_only=True) | ||||
|     serial = serializers.CharField(source='get_serial', read_only=True) | ||||
|     quantity = serializers.FloatField(read_only=True) | ||||
|  | ||||
|     # Extra detail fields | ||||
|     order_detail = SalesOrderSerializer(source='line.order', many=False, read_only=True) | ||||
|     part_detail = PartBriefSerializer(source='item.part', many=False, read_only=True) | ||||
|     item_detail = StockItemSerializer(source='item', many=False, read_only=True) | ||||
|  | ||||
|     def __init__(self, *args, **kwargs): | ||||
|  | ||||
|         order_detail = kwargs.pop('order_detail', False) | ||||
|         part_detail = kwargs.pop('part_detail', False) | ||||
|         item_detail = kwargs.pop('item_detail', False) | ||||
|  | ||||
|         super().__init__(*args, **kwargs) | ||||
|  | ||||
|         if not order_detail: | ||||
|             self.fields.pop('order_detail') | ||||
|  | ||||
|         if not part_detail: | ||||
|             self.fields.pop('part_detail') | ||||
|  | ||||
|         if not item_detail: | ||||
|             self.fields.pop('item_detail') | ||||
|  | ||||
|     class Meta: | ||||
|         model = SalesOrderAllocation | ||||
|  | ||||
| @@ -247,11 +268,12 @@ class SalesOrderAllocationSerializer(InvenTreeModelSerializer): | ||||
|             'line', | ||||
|             'serial', | ||||
|             'quantity', | ||||
|             'order', | ||||
|             'part', | ||||
|             'location', | ||||
|             'location_path', | ||||
|             'item', | ||||
|             'item_detail', | ||||
|             'order', | ||||
|             'order_detail', | ||||
|             'part', | ||||
|             'part_detail', | ||||
|         ] | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user