Skip to content

Commit

Permalink
fix: issues with addtional_information_required (hl-1566) (#3649)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirtawast authored Dec 13, 2024
1 parent d6cabc4 commit 3aa9281
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 31 deletions.
44 changes: 40 additions & 4 deletions backend/benefit/applications/api/v1/application_views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import re
from datetime import date
from datetime import date, timedelta
from decimal import Decimal, ROUND_DOWN
from typing import List

Expand Down Expand Up @@ -50,6 +50,7 @@
Application,
ApplicationAlteration,
ApplicationBatch,
ApplicationLogEntry,
)
from applications.services.ahjo_integration import (
ExportFileInfo,
Expand All @@ -71,6 +72,7 @@
get_context_for_summary_context,
)
from common.permissions import BFIsApplicant, BFIsHandler, TermsOfServiceAccepted
from messages.automatic_messages import send_application_reopened_message
from messages.models import MessageType
from shared.audit_log import audit_logging
from shared.audit_log.enums import Operation
Expand Down Expand Up @@ -858,14 +860,48 @@ def clone_as_draft(self, request, pk) -> HttpResponse:
@transaction.atomic
def require_additional_information(self, request, pk) -> HttpResponse:
application = self.get_object()
application_status = request.data["status"]
if application_status in [
to_status = request.data["status"]
from_status = application.status
if to_status in [
ApplicationStatus.ADDITIONAL_INFORMATION_NEEDED,
ApplicationStatus.HANDLING,
]:
application.status = application_status
ApplicationLogEntry.objects.create(
application=application,
from_status=from_status,
to_status=to_status,
comment="",
)

application.status = to_status
application.save()

if to_status == ApplicationStatus.ADDITIONAL_INFORMATION_NEEDED:
# Create an automatic message for the applicant
# self.instance.additional_information_requested_at is not updated at this point as
# it's a queryset annotation, so need to refresh
application.additional_information_requested_at = (
Application.objects.get(
pk=application.pk
).additional_information_requested_at
)

info_asked_timestamp = getattr(
application, "additional_information_requested_at", None
)
if info_asked_timestamp:
info_asked_timestamp = info_asked_timestamp.date() + timedelta(
days=7
)
else:
info_asked_timestamp = None

send_application_reopened_message(
request.user,
application,
info_asked_timestamp,
)

return Response(
status=status.HTTP_200_OK,
)
Expand Down
13 changes: 0 additions & 13 deletions backend/benefit/applications/api/v1/serializers/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
)
from companies.api.v1.serializers import CompanySearchSerializer, CompanySerializer
from companies.models import Company
from messages.automatic_messages import send_application_reopened_message
from shared.audit_log import audit_logging
from shared.audit_log.enums import Operation
from terms.api.v1.serializers import (
Expand Down Expand Up @@ -1197,18 +1196,6 @@ def handle_status_transition(
to_status=instance.status,
comment=log_entry_comment or "",
)
if instance.status == ApplicationStatus.ADDITIONAL_INFORMATION_NEEDED:
# Create an automatic message for the applicant
# self.instance.additional_information_requested_at is not updated at this point as
# it's a queryset annotation, so need to refresh
self.instance.additional_information_requested_at = Application.objects.get(
pk=instance.pk
).additional_information_requested_at
send_application_reopened_message(
get_request_user_from_context(self),
instance,
self.get_additional_information_needed_by(instance),
)

# Assign current user as handler
if (
Expand Down
36 changes: 24 additions & 12 deletions backend/benefit/applications/tests/test_applications_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1387,18 +1387,6 @@ def test_application_status_change_as_handler(
if handled_by_ahjo_automation:
assert response.data["handled_by_ahjo_automation"] is True

if to_status == ApplicationStatus.ADDITIONAL_INFORMATION_NEEDED:
assert application.messages.count() == 1
assert (
"Please make the corrections and send application again by 11.06.2021"
in application.messages.first().content
)
assert len(mailoutbox) == 1
assert (
get_additional_information_email_notification_subject()
in mailoutbox[0].subject
)

if to_status in [
ApplicationStatus.CANCELLED,
ApplicationStatus.REJECTED,
Expand Down Expand Up @@ -2436,6 +2424,30 @@ def test_applications_with_unread_messages(api_client, handler_api_client, appli
assert len(response.data) == 0


def test_require_additional_information(handler_api_client, application, mailoutbox):
application.status = ApplicationStatus.HANDLING
application.save()
response = handler_api_client.patch(
reverse(
"v1:handler-application-require-additional-information",
kwargs={"pk": application.id},
),
{"status": ApplicationStatus.ADDITIONAL_INFORMATION_NEEDED},
)
assert response.status_code == 200
print(response.__dict__)

assert application.messages.count() == 1
assert (
"Please make the corrections and send application again by 11.06.2021"
in application.messages.first().content
)
assert len(mailoutbox) == 1
assert (
get_additional_information_email_notification_subject() in mailoutbox[0].subject
)


def _create_random_applications():
f = faker.Faker()
combos = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export const renderPaymentTagPerStatus = (
</$TagWrapper>
);

const parseAhjoError = (ahjoError: AhjoError): JSX.Element[] => {
const renderAhjoError = (ahjoError: AhjoError): JSX.Element[] => {
if (Array.isArray(ahjoError.errorFromAhjo))
return ahjoError.errorFromAhjo.map(({ message }) => <li>{message}</li>);

Expand Down Expand Up @@ -190,7 +190,7 @@ const ApplicationList: React.FC<ApplicationListProps> = ({
Ahjo, {convertToUIDateAndTimeFormat(ahjoError?.modifiedAt)}
</strong>
</div>
<ul>{parseAhjoError(ahjoError)}</ul>
<ul>{renderAhjoError(ahjoError)}</ul>
</Tooltip>
</$ActionErrors>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const useRequireAdditionalInformation = (): UseMutationResult<
{
onSuccess: () => {
void queryClient.invalidateQueries('application');
void queryClient.invalidateQueries('messages');
void queryClient.invalidateQueries('applications');
},
onError: (error: AxiosError<Error, Record<string, string[]>>) => {
Expand Down

0 comments on commit 3aa9281

Please sign in to comment.