Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add two calculation and application fields as notes (hl-1550) #3549

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions backend/benefit/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1460,6 +1460,12 @@ msgstr ""
msgid "Handler is not allowed to do this action"
msgstr ""

msgid "Handling comment"
msgstr ""

msgid "Manual calculation comment"
msgstr ""

msgid "Only the terms currently in effect can be approved"
msgstr ""

Expand Down
6 changes: 6 additions & 0 deletions backend/benefit/locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,12 @@ msgstr "Hakija ei saa tehdä tätä toimenpidettä"
msgid "Handler is not allowed to do this action"
msgstr "Käsittelijä ei saa tehdä tätä toimenpidettä"

msgid "Handling comment"
msgstr "Käsittelyn perustelu"

msgid "Manual calculation comment"
msgstr "Manuaalisen laskelman perustelu"

msgid "Only the terms currently in effect can be approved"
msgstr "Vain voimassa olevat ehdot voidaan hyväksyä"

Expand Down
6 changes: 6 additions & 0 deletions backend/benefit/locale/sv/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,12 @@ msgstr "Sökande får inte utföra denna åtgärd"
msgid "Handler is not allowed to do this action"
msgstr "Handläggare får inte utföra denna åtgärd"

msgid "Handling comment"
msgstr ""

msgid "Manual calculation comment"
msgstr ""

msgid "Only the terms currently in effect can be approved"
msgstr "Endast de villkor som för tillfället gäller kan godkännas"

Expand Down
5 changes: 4 additions & 1 deletion backend/benefit/messages/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,10 @@ def test_update_message_unauthorized(
"message_type": msg_type,
},
)
assert result.status_code == 403

assert (
result.status_code == 403 if view_name == "handler-message-detail" else 404
)


def test_update_message_not_allowed(
Expand Down
72 changes: 69 additions & 3 deletions backend/benefit/messages/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from rest_framework.exceptions import NotFound
from rest_framework.response import Response

from applications.enums import ApplicationStatus
from applications.models import Application
from common.permissions import BFIsApplicant, BFIsHandler, TermsOfServiceAccepted
from messages.automatic_messages import (
Expand Down Expand Up @@ -109,9 +110,74 @@ def mark_unread(self, *args, **kwargs):
class HandlerNoteViewSet(HandlerMessageViewSet):
serializer_class = NoteSerializer

def get_queryset(self):
def list(self, request, *args, **kwargs):
try:
application = Application.objects.get(id=self.kwargs["application_pk"])
application = Application.objects.get(pk=self.kwargs["application_pk"])
except Application.DoesNotExist:
return Message.objects.none()
return application.messages.get_notes_qs()

messages = MessageSerializer(
application.messages.get_notes_qs(), many=True
).data

log_entry = (
application.log_entries.filter(
application_id=self.kwargs["application_pk"],
from_status=ApplicationStatus.HANDLING,
to_status__in=[ApplicationStatus.ACCEPTED, ApplicationStatus.REJECTED],
).first()
or None
)

if log_entry and application.status in [
ApplicationStatus.ACCEPTED,
ApplicationStatus.REJECTED,
]:
log_entry_comment = getattr(log_entry, "comment", None)
content = _("Handling comment") + ": " + log_entry_comment
if log_entry_comment is not None and log_entry_comment != "":
messages.append(
MessageSerializer(
Message(
id=getattr(log_entry, "id", None),
created_at=getattr(log_entry, "created_at", None),
modified_at=getattr(log_entry, "modified_at", None),
content=content,
message_type=MessageType.NOTE,
seen_by_applicant=True,
seen_by_handler=True,
)
).data
)

calculation_comment = (
(application.calculation.override_monthly_benefit_amount_comment)
if application.calculation
else None
)

if calculation_comment:
content = _("Manual calculation comment") + ": " + calculation_comment
messages.append(
MessageSerializer(
Message(
id=application.calculation.id,
created_at=getattr(application.calculation, "created_at", None),
modified_at=getattr(
application.calculation, "modified_at", None
),
content=content,
message_type=MessageType.NOTE,
seen_by_applicant=True,
seen_by_handler=True,
)
).data
)

if calculation_comment or log_entry:
messages.sort(key=lambda x: x["created_at"])

return Response(messages)


_("Manual calculation comment")
6 changes: 1 addition & 5 deletions backend/benefit/users/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ def get(self, request):
lang = request.GET.get("lang")

if lang in ["fi", "en", "sv"]:
token = request.COOKIES.get("yjdhcsrftoken")

response = Response(
{"lang": lang, "token": token}, status=status.HTTP_200_OK
)
response = Response({"lang": lang}, status=status.HTTP_200_OK)
response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang, httponly=True)
return response

Expand Down
20 changes: 18 additions & 2 deletions frontend/benefit/handler/src/components/header/useHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import axios from 'axios';
import NumberTag from 'benefit/handler/components/header/NumberTag';
import { ROUTES } from 'benefit/handler/constants';
import { ROUTES, SUPPORTED_LANGUAGES } from 'benefit/handler/constants';
import AppContext from 'benefit/handler/context/AppContext';
import useApplicationAlterationsQuery from 'benefit/handler/hooks/useApplicationAlterationsQuery';
import { useDetermineAhjoMode } from 'benefit/handler/hooks/useDetermineAhjoMode';
import {
BackendEndpoint,
getBackendDomain,
} from 'benefit-shared/backend-api/backend-api';
import { useRouter } from 'next/router';
import { TFunction, useTranslation } from 'next-i18next';
import React from 'react';
import React, { useEffect } from 'react';
import { NavigationItem, OptionType } from 'shared/types/common';
import { getLanguageOptions } from 'shared/utils/common';

const setLanguageToFinnish = (): void => {
const optionsEndpoint = `${getBackendDomain()}/${
BackendEndpoint.USER_OPTIONS
}`;
void axios.get(optionsEndpoint, {
params: { lang: SUPPORTED_LANGUAGES.FI },
});
};

type ExtendedComponentProps = {
t: TFunction;
languageOptions: OptionType<string>[];
Expand All @@ -33,6 +47,8 @@ const useHeader = (): ExtendedComponentProps => {
[t]
);

useEffect(setLanguageToFinnish, []);

const { data: alterationData, isLoading: isAlterationListLoading } =
useApplicationAlterationsQuery();

Expand Down
Loading