Skip to content

Commit

Permalink
Add separate serializer for exporter licence details
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincarrogan committed Sep 25, 2024
1 parent 64808e3 commit 8f16323
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
50 changes: 50 additions & 0 deletions api/licences/serializers/view_licence.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,53 @@ class Meta:
)
read_only_fields = fields
ordering = ["created_at"]


class GoodOnLicenceExporterLicenceViewSerializer(serializers.ModelSerializer):
applied_for_quantity = serializers.FloatField(source="good.quantity")
assessed_control_list_entries = ControlListEntrySerializer(source="good.control_list_entries", many=True)
control_list_entries = ControlListEntrySerializer(source="good.good.control_list_entries", many=True)
description = serializers.CharField(source="good.good.description")
licenced_quantity = serializers.FloatField(source="quantity")
licenced_value = serializers.FloatField(source="value")
units = KeyValueChoiceField(source="good.unit", choices=Units.choices)
usage = serializers.FloatField()

class Meta:
model = GoodOnLicence
fields = (
"id",
"applied_for_quantity",
"assessed_control_list_entries",
"control_list_entries",
"description",
"licenced_quantity",
"licenced_value",
"units",
"usage",
)
read_only_fields = fields


class ExporterLicenceViewSerializer(serializers.ModelSerializer):
application = ApplicationLicenceSerializer(source="case.baseapplication")
document = serializers.SerializerMethodField()
status = KeyValueChoiceField(choices=LicenceStatus.choices)
goods = GoodOnLicenceExporterLicenceViewSerializer(many=True)

class Meta:
model = Licence
fields = (
"id",
"application",
"document",
"duration",
"start_date",
"status",
"goods",
)
read_only_fields = fields

def get_document(self, instance):
document = GeneratedCaseDocument.objects.get(licence=instance)
return {"id": document.id}
4 changes: 2 additions & 2 deletions api/licences/views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from api.licences.enums import LicenceStatus
from api.licences.models import Licence
from api.licences.serializers.view_licence import (
ExporterLicenceViewSerializer,
LicenceDetailsSerializer,
LicenceSerializer,
NLRdocumentSerializer,
LicenceListSerializer,
)
Expand Down Expand Up @@ -86,7 +86,7 @@ def get_queryset(self):

class ViewLicence(RetrieveAPIView):
authentication_classes = (ExporterAuthentication,)
serializer_class = LicenceSerializer
serializer_class = ExporterLicenceViewSerializer

def get_queryset(self):
return Licence.objects.filter(case__organisation_id=get_request_user_organisation_id(self.request))
Expand Down

0 comments on commit 8f16323

Please sign in to comment.