mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	Adds ability to list part parameters via the Part API
This commit is contained in:
		@@ -12,11 +12,16 @@ import common.models
 | 
				
			|||||||
INVENTREE_SW_VERSION = "0.7.0 dev"
 | 
					INVENTREE_SW_VERSION = "0.7.0 dev"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# InvenTree API version
 | 
					# InvenTree API version
 | 
				
			||||||
INVENTREE_API_VERSION = 31
 | 
					INVENTREE_API_VERSION = 32
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
Increment this API version number whenever there is a significant change to the API that any clients need to know about
 | 
					Increment this API version number whenever there is a significant change to the API that any clients need to know about
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					v32 -> 2022-03-19
 | 
				
			||||||
 | 
					    - Adds "parameters" detail to Part API endpoint (use ¶meters=true)
 | 
				
			||||||
 | 
					    - Adds ability to filter PartParameterTemplate API by Part instance
 | 
				
			||||||
 | 
					    - Adds ability to filter PartParameterTemplate API by PartCategory instance
 | 
				
			||||||
 | 
					
 | 
				
			||||||
v31 -> 2022-03-14
 | 
					v31 -> 2022-03-14
 | 
				
			||||||
    - Adds "updated" field to SupplierPriceBreakList and SupplierPriceBreakDetail API endpoints
 | 
					    - Adds "updated" field to SupplierPriceBreakList and SupplierPriceBreakDetail API endpoints
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -855,6 +855,14 @@ class PartList(generics.ListCreateAPIView):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        kwargs['starred_parts'] = self.starred_parts
 | 
					        kwargs['starred_parts'] = self.starred_parts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            params = self.request.query_params
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            kwargs['parameters'] = str2bool(params.get('parameters', None))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        except AttributeError:
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return self.serializer_class(*args, **kwargs)
 | 
					        return self.serializer_class(*args, **kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def list(self, request, *args, **kwargs):
 | 
					    def list(self, request, *args, **kwargs):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -211,6 +211,34 @@ class PartThumbSerializerUpdate(InvenTreeModelSerializer):
 | 
				
			|||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class PartParameterTemplateSerializer(InvenTreeModelSerializer):
 | 
				
			||||||
 | 
					    """ JSON serializer for the PartParameterTemplate model """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class Meta:
 | 
				
			||||||
 | 
					        model = PartParameterTemplate
 | 
				
			||||||
 | 
					        fields = [
 | 
				
			||||||
 | 
					            'pk',
 | 
				
			||||||
 | 
					            'name',
 | 
				
			||||||
 | 
					            'units',
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class PartParameterSerializer(InvenTreeModelSerializer):
 | 
				
			||||||
 | 
					    """ JSON serializers for the PartParameter model """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    template_detail = PartParameterTemplateSerializer(source='template', many=False, read_only=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class Meta:
 | 
				
			||||||
 | 
					        model = PartParameter
 | 
				
			||||||
 | 
					        fields = [
 | 
				
			||||||
 | 
					            'pk',
 | 
				
			||||||
 | 
					            'part',
 | 
				
			||||||
 | 
					            'template',
 | 
				
			||||||
 | 
					            'template_detail',
 | 
				
			||||||
 | 
					            'data'
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PartBriefSerializer(InvenTreeModelSerializer):
 | 
					class PartBriefSerializer(InvenTreeModelSerializer):
 | 
				
			||||||
    """ Serializer for Part (brief detail) """
 | 
					    """ Serializer for Part (brief detail) """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -259,11 +287,16 @@ class PartSerializer(InvenTreeModelSerializer):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        category_detail = kwargs.pop('category_detail', False)
 | 
					        category_detail = kwargs.pop('category_detail', False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        parameters = kwargs.pop('parameters', False)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        super().__init__(*args, **kwargs)
 | 
					        super().__init__(*args, **kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if category_detail is not True:
 | 
					        if category_detail is not True:
 | 
				
			||||||
            self.fields.pop('category_detail')
 | 
					            self.fields.pop('category_detail')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if parameters is not True:
 | 
				
			||||||
 | 
					            self.fields.pop('parameters')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @staticmethod
 | 
					    @staticmethod
 | 
				
			||||||
    def annotate_queryset(queryset):
 | 
					    def annotate_queryset(queryset):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
@@ -356,19 +389,18 @@ class PartSerializer(InvenTreeModelSerializer):
 | 
				
			|||||||
    # PrimaryKeyRelated fields (Note: enforcing field type here results in much faster queries, somehow...)
 | 
					    # PrimaryKeyRelated fields (Note: enforcing field type here results in much faster queries, somehow...)
 | 
				
			||||||
    category = serializers.PrimaryKeyRelatedField(queryset=PartCategory.objects.all())
 | 
					    category = serializers.PrimaryKeyRelatedField(queryset=PartCategory.objects.all())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # TODO - Include annotation for the following fields:
 | 
					    parameters = PartParameterSerializer(
 | 
				
			||||||
    # allocated_stock = serializers.FloatField(source='allocation_count', read_only=True)
 | 
					        many=True,
 | 
				
			||||||
    # bom_items = serializers.IntegerField(source='bom_count', read_only=True)
 | 
					        read_only=True,
 | 
				
			||||||
    # used_in = serializers.IntegerField(source='used_in_count', read_only=True)
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    class Meta:
 | 
					    class Meta:
 | 
				
			||||||
        model = Part
 | 
					        model = Part
 | 
				
			||||||
        partial = True
 | 
					        partial = True
 | 
				
			||||||
        fields = [
 | 
					        fields = [
 | 
				
			||||||
            'active',
 | 
					            'active',
 | 
				
			||||||
            # 'allocated_stock',
 | 
					
 | 
				
			||||||
            'assembly',
 | 
					            'assembly',
 | 
				
			||||||
            # 'bom_items',
 | 
					 | 
				
			||||||
            'category',
 | 
					            'category',
 | 
				
			||||||
            'category_detail',
 | 
					            'category_detail',
 | 
				
			||||||
            'component',
 | 
					            'component',
 | 
				
			||||||
@@ -388,6 +420,7 @@ class PartSerializer(InvenTreeModelSerializer):
 | 
				
			|||||||
            'minimum_stock',
 | 
					            'minimum_stock',
 | 
				
			||||||
            'name',
 | 
					            'name',
 | 
				
			||||||
            'notes',
 | 
					            'notes',
 | 
				
			||||||
 | 
					            'parameters',
 | 
				
			||||||
            'pk',
 | 
					            'pk',
 | 
				
			||||||
            'purchaseable',
 | 
					            'purchaseable',
 | 
				
			||||||
            'revision',
 | 
					            'revision',
 | 
				
			||||||
@@ -398,7 +431,6 @@ class PartSerializer(InvenTreeModelSerializer):
 | 
				
			|||||||
            'thumbnail',
 | 
					            'thumbnail',
 | 
				
			||||||
            'trackable',
 | 
					            'trackable',
 | 
				
			||||||
            'units',
 | 
					            'units',
 | 
				
			||||||
            # 'used_in',
 | 
					 | 
				
			||||||
            'variant_of',
 | 
					            'variant_of',
 | 
				
			||||||
            'virtual',
 | 
					            'virtual',
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
@@ -600,34 +632,6 @@ class BomItemSerializer(InvenTreeModelSerializer):
 | 
				
			|||||||
        ]
 | 
					        ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PartParameterTemplateSerializer(InvenTreeModelSerializer):
 | 
					 | 
				
			||||||
    """ JSON serializer for the PartParameterTemplate model """
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    class Meta:
 | 
					 | 
				
			||||||
        model = PartParameterTemplate
 | 
					 | 
				
			||||||
        fields = [
 | 
					 | 
				
			||||||
            'pk',
 | 
					 | 
				
			||||||
            'name',
 | 
					 | 
				
			||||||
            'units',
 | 
					 | 
				
			||||||
        ]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class PartParameterSerializer(InvenTreeModelSerializer):
 | 
					 | 
				
			||||||
    """ JSON serializers for the PartParameter model """
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    template_detail = PartParameterTemplateSerializer(source='template', many=False, read_only=True)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    class Meta:
 | 
					 | 
				
			||||||
        model = PartParameter
 | 
					 | 
				
			||||||
        fields = [
 | 
					 | 
				
			||||||
            'pk',
 | 
					 | 
				
			||||||
            'part',
 | 
					 | 
				
			||||||
            'template',
 | 
					 | 
				
			||||||
            'template_detail',
 | 
					 | 
				
			||||||
            'data'
 | 
					 | 
				
			||||||
        ]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class CategoryParameterTemplateSerializer(InvenTreeModelSerializer):
 | 
					class CategoryParameterTemplateSerializer(InvenTreeModelSerializer):
 | 
				
			||||||
    """ Serializer for PartCategoryParameterTemplate """
 | 
					    """ Serializer for PartCategoryParameterTemplate """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user