Skip to content

Commit

Permalink
feat: add localization for ahjo messages (#2891)
Browse files Browse the repository at this point in the history
  • Loading branch information
rikuke authored Mar 22, 2024
1 parent ebbe9e5 commit 943be9d
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 24 deletions.
9 changes: 9 additions & 0 deletions backend/benefit/applications/services/ahjo_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.db.models import F, OuterRef, QuerySet, Subquery
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils import translation

from applications.enums import (
AhjoRequestType,
Expand Down Expand Up @@ -395,12 +396,20 @@ def generate_secret_xml_string(application: Application) -> str:
row_type=RowType.HELSINKI_BENEFIT_SUB_TOTAL_EUR
)

# Set the locale for this thread to the application's language
translation.activate(application.applicant_language)

context = {
"application": application,
"benefit_type": "Palkan Helsinki-lisä",
"calculation_rows": sub_total_rows,
"language": application.applicant_language,
}
xml_content = render_to_string("secret_decision.xml", context)

# Reset the locale to the default
translation.deactivate()

return xml_content


Expand Down
8 changes: 5 additions & 3 deletions backend/benefit/applications/services/ahjo_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ def _prepare_top_level_dict(
) -> dict:
"""Prepare the dictionary that is sent to Ahjo"""
application_date = application.created_at.isoformat("T", "seconds")
language = application.applicant_language

handler = application.calculation.handler
case_dict = {
"Title": case_title,
"Acquired": application_date,
"ClassificationCode": "02 05 01 00",
"ClassificationTitle": "Kunnan myöntämät avustukset",
"Language": "fi",
"Language": language,
"PublicityClass": "Julkinen",
"InternalTitle": case_title,
"Subjects": [
Expand Down Expand Up @@ -191,6 +192,7 @@ def prepare_decision_proposal_payload(
inspector_dict = {"Role": "inspector", "Name": "Tarkastaja, Tero", "ID": "terot"}
# TODO remove hard coded decision maker
decision_maker_dict = {"Role": "decisionMaker", "ID": "U02120013070VH2"}
language = application.applicant_language

main_creator_dict = {
"Role": "mainCreator",
Expand All @@ -204,7 +206,7 @@ def prepare_decision_proposal_payload(
"Title": "Avustuksen myöntäminen, Työllisyyspalvelut, työllisyydenhoidon Helsinki-lisä vuonna 2024",
"Type": "viranhaltijan päätös",
"PublicityClass": "Julkinen",
"Language": "fi",
"Language": language,
"PersonalData": "Sisältää henkilötietoja",
"Documents": [_prepare_record_document_dict(decision_xml)],
"Agents": [
Expand All @@ -218,7 +220,7 @@ def prepare_decision_proposal_payload(
"Type": "viranhaltijan päätöksen liite",
"PublicityClass": "Salassa pidettävä",
"SecurityReasons": ["JulkL (621/1999) 24.1 § 25 k"],
"Language": "fi",
"Language": language,
"PersonalData": "Sisältää erityisiä henkilötietoja",
"Documents": [_prepare_record_document_dict(secret_xml)],
"Agents": [main_creator_dict],
Expand Down
41 changes: 21 additions & 20 deletions backend/benefit/applications/templates/secret_decision.xml
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
{% load i18n %}
<body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Hki-lisa_paatosXML_AA-2030/hkilisa-paatosteksti.xsd">
<main id="paatoksenliite" lang="fi">
<h1>Työllisyydenhoidon Helsinki-lisän myöntäminen</h1>
<main id="paatoksenliite" lang="{{language}}">
<h1>{{ _("Granting of Helsinki-lisä benefit") }}</h1>
<table class="twocols-noborders">
<tbody>
<tr>
<th scope="row">Hakemusnumero</th>
<td>{{application.application_number}}</td>
<th scope="row">{{ _("Application number") }}</th>
<td>{{ application.application_number }}</td>
</tr>
<tr>
<th scope="row">Hakija</th>
<td>{{application.company.name}}</td>
<th scope="row">{{ _("applicant") }}</th>
<td>{{ application.company.name }}</td>
</tr>
<tr>
<th scope="row">Y-tunnus</th>
<td>{{application.company.business_id}}</td>
<th scope="row">{{ _("Business ID") }}</th>
<td>{{ application.company.business_id }}</td>
</tr>
<tr>
<th scope="row">Työllistetyn sukunimi</th>
<td>{{application.employee.last_name}}</td>
<th scope="row">{{ _("Employee last name") }}</th>
<td>{{ application.employee.last_name }}</td>
</tr>
<tr>
<th scope="row">Työllistetyn etunimi</th>
<td>{{application.employee.first_name}}</td>
<th scope="row">{{ _("Employee first name") }}</th>
<td>{{ application.employee.first_name }}</td>
</tr>
<tr>
<th scope="row">Tukimuoto</th>
<td>{{benefit_type}}</td>
<th scope="row">{{ _("Benefit type") }}</th>
<td>{{ benefit_type }}</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>aika</th>
<th>tuki/kk</th>
<th>tuki yhteensä €</th>
<th>{{ _("Applying for dates") }}</th>
<th>{{ _("Benefit per month") }}</th>
<th>{{ _("Total benefit") }}€</th>
</tr>
</thead>
<tbody>
{% for row in calculation_rows %}
<tr>
<td>{{row.start_date|date:"d.m.Y"}} - {{row.end_date|date:"d.m.Y"}}</td>
<td>{{row.amount}}</td>
<th>{{application.calculation.calculated_benefit_amount}}</th>
<td>{{ row.start_date|date:"d.m.Y" }} - {{ row.end_date|date:"d.m.Y" }}</td>
<td>{{ row.amount }}</td>
<th>{{ application.calculation.calculated_benefit_amount }}</th>
</tr>
{% endfor %}
</tbody>
Expand Down
3 changes: 2 additions & 1 deletion backend/benefit/applications/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ def ahjo_payload_record_for_attachment_update(
@pytest.fixture()
def ahjo_open_case_top_level_dict(decided_application):
application = decided_application
language = application.applicant_language

handler = application.calculation.handler

Expand All @@ -367,7 +368,7 @@ def ahjo_open_case_top_level_dict(decided_application):
"Acquired": application.created_at.isoformat(),
"ClassificationCode": "02 05 01 00",
"ClassificationTitle": "Kunnan myöntämät avustukset",
"Language": "fi",
"Language": language,
"PublicityClass": "Julkinen",
"InternalTitle": "message title",
"Subjects": [
Expand Down
12 changes: 12 additions & 0 deletions backend/benefit/applications/tests/test_ahjo_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
ExportFileInfo,
generate_application_attachment,
generate_composed_files,
generate_secret_xml_string,
generate_single_approved_file,
generate_single_declined_file,
get_application_for_ahjo,
Expand Down Expand Up @@ -659,6 +660,17 @@ def test_get_applications_for_open_case(
assert applications_for_open_case.count() == len(multiple_handling_applications)


@pytest.mark.django_db
def test_generate_secret_xml_string(decided_application):
application = decided_application
xml_content = generate_secret_xml_string(application)

wanted_language = application.applicant_language

# Check if the returned XML string contains the expected content
assert f'<main id="paatoksenliite" lang="{wanted_language}">' in xml_content


@pytest.mark.django_db
def test_prepare_delete_url(settings, decided_application):
application = decided_application
Expand Down
19 changes: 19 additions & 0 deletions backend/benefit/locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,25 @@ msgstr "palveluehtojen hyväksyntä"
msgid "terms of service approvals"
msgstr "palveluehtojen hyväksynnät"

# For Ahjo secret decision XML
msgid "Granting of Helsinki-lisä benefit"
msgstr "Työllisyydenhoidon Helsinki-lisän myöntäminen"

msgid "Benefit type"
msgstr "Tukimuoto"

msgid "Total benefit"
msgstr "tuki yhteensä"

msgid "Benefit per month"
msgstr "tuki/kk"

msgid "Employee first name"
msgstr "Työllistetyn etunimi"

msgid "Employee last name"
msgstr "Työllistetyn sukunimi"

#~ msgid "applicant"
#~ msgstr "hakija"

Expand Down
19 changes: 19 additions & 0 deletions backend/benefit/locale/sv/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,25 @@ msgstr "godkännande av villkoren för tjänsten"
msgid "terms of service approvals"
msgstr "godkännanden av villkoren för tjänsten"

# For Ahjo secret decision XML
msgid "Granting of Helsinki-lisä benefit"
msgstr "Beviljande av Helsingforstillägget för anställningsstöd"

msgid "Benefit type"
msgstr "Typ av förmån"

msgid "Total benefit"
msgstr "total förmån"

msgid "Benefit per month"
msgstr "förmån per månad"

msgid "Employee first name"
msgstr "anställdas förnamn"

msgid "Employee last name"
msgstr "anställdas efternamn"

#~ msgid "applicant"
#~ msgstr "sökande"

Expand Down

0 comments on commit 943be9d

Please sign in to comment.