From 8b1bde49eda3651cb817bbb8b5d01e3692b5c442 Mon Sep 17 00:00:00 2001 From: Aakash Singh Date: Wed, 21 Aug 2024 16:04:48 +0530 Subject: [PATCH] Use new serializer for assets --- care/facility/api/serializers/asset.py | 26 ++++++++++++++++++++++++++ care/facility/api/viewsets/asset.py | 5 +++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/care/facility/api/serializers/asset.py b/care/facility/api/serializers/asset.py index 88ad84fa52..57526a8ba6 100644 --- a/care/facility/api/serializers/asset.py +++ b/care/facility/api/serializers/asset.py @@ -320,6 +320,32 @@ def update(self, instance: Asset, validated_data): return updated_instance +class AssetPublicSerializer(ModelSerializer): + id = UUIDField(source="external_id", read_only=True) + status = ChoiceField(choices=StatusChoices, read_only=True) + asset_type = ChoiceField(choices=AssetTypeChoices) + location_object = AssetLocationSerializer(source="current_location", read_only=True) + + class Meta: + model = Asset + fields = ( + "id", + "name", + "location_object", + "serial_number", + "warranty_details", + "warranty_amc_end_of_validity", + "asset_type", + "asset_class", + "vendor_name", + "support_name", + "support_email", + "support_phone", + "is_working", + "status", + ) + + class AssetConfigSerializer(ModelSerializer): id = UUIDField(source="external_id") type = CharField(source="asset_class") diff --git a/care/facility/api/viewsets/asset.py b/care/facility/api/viewsets/asset.py index 45b976f2f9..42323de545 100644 --- a/care/facility/api/viewsets/asset.py +++ b/care/facility/api/viewsets/asset.py @@ -35,6 +35,7 @@ from care.facility.api.serializers.asset import ( AssetConfigSerializer, AssetLocationSerializer, + AssetPublicSerializer, AssetSerializer, AssetServiceSerializer, AssetTransactionSerializer, @@ -187,7 +188,7 @@ def filter_is_permanent(self, queryset, _, value): class AssetPublicViewSet(GenericViewSet): queryset = Asset.objects.all() - serializer_class = AssetSerializer + serializer_class = AssetPublicSerializer lookup_field = "external_id" def retrieve(self, request, *args, **kwargs): @@ -205,7 +206,7 @@ def retrieve(self, request, *args, **kwargs): class AssetPublicQRViewSet(GenericViewSet): queryset = Asset.objects.all() - serializer_class = AssetSerializer + serializer_class = AssetPublicSerializer lookup_field = "qr_code_id" def retrieve(self, request, *args, **kwargs):