Skip to content

Commit

Permalink
Use new serializer for assets
Browse files Browse the repository at this point in the history
  • Loading branch information
sainak committed Aug 21, 2024
1 parent 68a3a82 commit 8b1bde4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
26 changes: 26 additions & 0 deletions care/facility/api/serializers/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 3 additions & 2 deletions care/facility/api/viewsets/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from care.facility.api.serializers.asset import (
AssetConfigSerializer,
AssetLocationSerializer,
AssetPublicSerializer,
AssetSerializer,
AssetServiceSerializer,
AssetTransactionSerializer,
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 8b1bde4

Please sign in to comment.