diff --git a/InvenTree/part/api.py b/InvenTree/part/api.py index ec599de446..e032c73eeb 100644 --- a/InvenTree/part/api.py +++ b/InvenTree/part/api.py @@ -243,6 +243,12 @@ class PartList(generics.ListCreateAPIView): else: item['category__name'] = None + # Rename "URL" to "link" to distinguish from lower-case "url", + # which is the web address of the item itself + if 'URL' in item.keys(): + item['link'] = item['URL'] + del item['URL'] + return Response(data) def get_queryset(self): diff --git a/InvenTree/part/serializers.py b/InvenTree/part/serializers.py index a48aaaa54d..9e97cad84f 100644 --- a/InvenTree/part/serializers.py +++ b/InvenTree/part/serializers.py @@ -78,12 +78,16 @@ class PartSerializer(InvenTreeModelSerializer): Used when displaying all details of a single component. """ - url = serializers.CharField(source='get_absolute_url', read_only=True) - image = serializers.CharField(source='get_image_url', read_only=True) - thumbnail = serializers.CharField(source='get_thumbnail_url', read_only=True) + allocated_stock = serializers.FloatField(source='allocation_count', read_only=True) + bom_items = serializers.IntegerField(source='bom_count', read_only=True) + building = serializers.FloatField(source='quantity_being_built', read_only=False) category_name = serializers.CharField(source='category_path', read_only=True) - - allocated_stock = serializers.IntegerField(source='allocation_count', read_only=True) + image = serializers.CharField(source='get_image_url', read_only=True) + on_order = serializers.FloatField(read_only=True) + thumbnail = serializers.CharField(source='get_thumbnail_url', read_only=True) + url = serializers.CharField(source='get_absolute_url', read_only=True) + link = serializers.CharField(source='URL') + used_in = serializers.IntegerField(source='used_in_count', read_only=True) @staticmethod def setup_eager_loading(queryset): @@ -97,31 +101,34 @@ class PartSerializer(InvenTreeModelSerializer): model = Part partial = True fields = [ - 'pk', - 'url', # Link to the part detail page + 'active', + 'allocated_stock', + 'assembly', + 'bom_items', + 'building', 'category', 'category_name', - 'image', - 'thumbnail', + 'component', + 'description', 'full_name', - 'name', + 'image', 'IPN', 'is_template', - 'variant_of', - 'description', 'keywords', - 'URL', - 'total_stock', - 'allocated_stock', + 'link', + 'name', + 'notes', 'on_order', - 'units', - 'trackable', - 'assembly', - 'component', - 'trackable', + 'pk', 'purchaseable', 'salable', - 'active', + 'thumbnail', + 'trackable', + 'total_stock', + 'units', + 'used_in', + 'url', # Link to the part detail page + 'variant_of', 'virtual', ]