diff --git a/backend/benefit/applications/api/v1/serializers/application.py b/backend/benefit/applications/api/v1/serializers/application.py index ba04c748d7..7a536201c1 100755 --- a/backend/benefit/applications/api/v1/serializers/application.py +++ b/backend/benefit/applications/api/v1/serializers/application.py @@ -1472,15 +1472,10 @@ class ApplicantApplicationSerializer(BaseApplicationSerializer): ), ) - batch = SimpleApplicationBatchSerializer( - allow_null=True, - required=False, - ) + has_batch = serializers.SerializerMethodField() - def get_batch(self, _): - if self.batch: - return True - return None + def get_has_batch(self, obj): + return obj.batch is not None changes = serializers.SerializerMethodField( help_text=("Possible changes made by handler to the application."), @@ -1510,7 +1505,7 @@ def update(self, instance, validated_data): return self._base_update(instance, validated_data) class Meta(BaseApplicationSerializer.Meta): - fields = BaseApplicationSerializer.Meta.fields + ["batch"] + fields = BaseApplicationSerializer.Meta.fields + ["batch", "has_batch"] class HandlerApplicationSerializer(BaseApplicationSerializer): diff --git a/backend/benefit/applications/tests/test_applications_api.py b/backend/benefit/applications/tests/test_applications_api.py index 255b93dec6..102a8b24bf 100755 --- a/backend/benefit/applications/tests/test_applications_api.py +++ b/backend/benefit/applications/tests/test_applications_api.py @@ -3,6 +3,7 @@ import os import re import tempfile +import uuid from datetime import date, datetime, timedelta, timezone from decimal import Decimal from unittest import mock @@ -376,7 +377,7 @@ def test_application_single_read_without_ahjo_decision_as_applicant( assert response.data["ahjo_decision"] is None assert response.data["application_number"] is not None assert response.data["status"] == visible_status - assert response.data["batch"] is None + assert response.data["has_batch"] is False assert Decimal(response.data["duration_in_months_rounded"]) == duration_in_months( application.start_date, application.end_date, decimal_places=2 ) @@ -387,7 +388,8 @@ def test_application_single_read_without_ahjo_decision_as_applicant( response = api_client.get(get_detail_url(application)) assert response.status_code == 200 - assert response.data["batch"] is True + assert response.data["has_batch"] is True + assert isinstance(response.data["batch"], uuid.UUID) @pytest.mark.parametrize( @@ -410,7 +412,9 @@ def test_application_single_read_with_ahjo_decision_as_applicant( assert response.data["ahjo_decision"] is not None assert response.data["application_number"] is not None assert response.data["status"] == visible_status - assert response.data["batch"] is True + assert response.data["has_batch"] is True + + assert isinstance(response.data["batch"], uuid.UUID) assert Decimal(response.data["duration_in_months_rounded"]) == duration_in_months( application.start_date, application.end_date, decimal_places=2 ) diff --git a/frontend/benefit/applicant/src/components/header/useHeader.ts b/frontend/benefit/applicant/src/components/header/useHeader.ts index a6625238f0..cdf23d4354 100644 --- a/frontend/benefit/applicant/src/components/header/useHeader.ts +++ b/frontend/benefit/applicant/src/components/header/useHeader.ts @@ -50,7 +50,7 @@ const useHeader = (): ExtendedComponentProps => { ); const { data: application } = useApplicationQuery(id); - const canWriteNewMessages = !application?.batch; + const canWriteNewMessages = !application?.has_batch; useEffect(() => { if (application?.unread_messages_count) { diff --git a/frontend/benefit/shared/src/types/application.d.ts b/frontend/benefit/shared/src/types/application.d.ts index 369e8af630..9d937f3bbd 100644 --- a/frontend/benefit/shared/src/types/application.d.ts +++ b/frontend/benefit/shared/src/types/application.d.ts @@ -441,6 +441,7 @@ export type ApplicationData = { training_compensations: TrainingCompensationData[]; handled_at?: string; batch?: BatchData; + has_batch?: boolean; latest_decision_comment?: string; unread_messages_count?: number; application_origin?: APPLICATION_ORIGINS;