Skip to content

Commit

Permalink
chore(handler): use optimized serializer to list applications (hl-143…
Browse files Browse the repository at this point in the history
…2) (#3226)

* chore: use optimized serializer to list applications

* fix: remove old serializer's test lines
  • Loading branch information
sirtawast authored Sep 6, 2024
1 parent f85cb31 commit 6a6100d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion backend/benefit/applications/api/v1/application_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ def simplified_application_list(self, request):
status=ApplicationStatus.DRAFT,
application_origin=ApplicationOrigin.APPLICANT,
)
serializer = self.serializer_class(qs, many=True, context=context)
serializer = HandlerApplicationListSerializer(qs, many=True, context=context)

return Response(
serializer.data,
Expand Down
14 changes: 14 additions & 0 deletions backend/benefit/applications/api/v1/serializers/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,8 @@ class Meta:
"additional_information_needed_by",
"calculation",
"alterations",
"archived",
"handled_by_ahjo_automation",
]

read_only_fields = [
Expand All @@ -1906,8 +1908,12 @@ class Meta:
"handler",
"calculation",
"alterations",
"archived",
"handled_by_ahjo_automation",
]

archived = serializers.BooleanField()

additional_information_needed_by = serializers.SerializerMethodField(
"get_additional_information_needed_by"
)
Expand All @@ -1925,6 +1931,14 @@ class Meta:
),
)

handled_by_ahjo_automation = serializers.BooleanField(
read_only=True,
required=False,
help_text=(
"True if the application has been handled by the Ahjo automation system"
),
)

application_number = serializers.IntegerField()

status = serializers.ChoiceField(
Expand Down
5 changes: 0 additions & 5 deletions backend/benefit/applications/tests/test_applications_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,9 @@ def test_applications_simple_list_exclude_more(
):
response = handler_api_client.get(
reverse("v1:handler-application-simplified-application-list")
+ f"?exclude_fields={','.join(exclude_fields)}"
)
assert len(response.data) == 1
assert response.status_code == 200
for key in exclude_fields:
assert key not in response.data[0]
for key in BaseApplicationViewSet.EXCLUDE_FIELDS_FROM_SIMPLE_LIST:
assert key not in response.data[0]


def test_applications_simple_list_filter(
Expand Down
19 changes: 11 additions & 8 deletions backend/benefit/calculator/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,14 @@ class Meta:
class CalculationSearchSerializer(serializers.ModelSerializer):
class Meta:
model = Calculation
fields = [
"start_date",
"end_date",
]
read_only_fields = [
"start_date",
"end_date",
]
fields = ["start_date", "end_date", "handler_details"]
read_only_fields = ["start_date", "end_date", "handler_details"]

handler_details = UserSerializer(
help_text=(
"The handler object, with fields, currently assigned to this calculation"
" and application (read-only)"
),
read_only=True,
source="handler",
)

0 comments on commit 6a6100d

Please sign in to comment.