Skip to content

Commit

Permalink
feat: specify Excel exporter's salary & sum fields as €, cast sum as int
Browse files Browse the repository at this point in the history
related:
#2745 (comment)

refs YJDH-683
  • Loading branch information
karisal-anders committed Jan 23, 2024
1 parent 6a527ba commit 401f815
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 19 deletions.
21 changes: 14 additions & 7 deletions backend/kesaseteli/applications/exporters/excel_exporter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import io
from typing import Iterable, List, NamedTuple
from typing import Iterable, List, Literal, NamedTuple

from django.db.models import QuerySet
from django.http import HttpRequest
Expand All @@ -13,13 +13,16 @@
from applications.models import EmployerSummerVoucher
from common.utils import getattr_nested

ExcelFieldType = Literal["int", "str"]


class ExcelField(NamedTuple):
title: str
value: str
model_fields: List[str]
width: int
background_color: str
type: ExcelFieldType = "str"


APPLICATION_LANGUAGE_FIELD_TITLE = _("Hakemuksen kieli")
Expand All @@ -29,9 +32,9 @@ class ExcelField(NamedTuple):
HIRED_WITHOUT_VOUCHER_ASSESSMENT_FIELD_TITLE = _("Olisitko palkannut?")
ORDER_FIELD_TITLE = _("Järjestys")
RECEIVED_DATE_FIELD_TITLE = _("Saatu pvm")
SALARY_PAID_FIELD_TITLE = _("Maksettu palkka")
SALARY_PAID_FIELD_TITLE = _("Maksettu palkka (€)")
SPECIAL_CASE_FIELD_TITLE = _("Erikoistapaus (esim yhdeksäsluokkalainen)")
SUM_FIELD_TITLE = _("Summa")
SUM_FIELD_TITLE = _("Summa (€)")
WORK_HOURS_FIELD_TITLE = _("Työtunnit")
INVOICER_EMAIL_FIELD_TITLE = _("Laskuttajan sähköposti")
INVOICER_NAME_FIELD_TITLE = _("Laskuttajan nimi")
Expand Down Expand Up @@ -245,7 +248,7 @@ class ExcelField(NamedTuple):
30,
"#F7DAE3",
),
ExcelField(SUM_FIELD_TITLE, "%s", ["value_in_euros"], 15, "#F7DAE3"),
ExcelField(SUM_FIELD_TITLE, "%s", ["value_in_euros"], 15, "#F7DAE3", "int"),
ExcelField(_("Tarkastaja etunimi"), "", [], 30, "#F7DAE3"),
ExcelField(_("Tarkastaja sukunimi"), "", [], 30, "#F7DAE3"),
ExcelField(_("Hyväksyjä etunimi"), "", [], 30, "#F7DAE3"),
Expand Down Expand Up @@ -368,11 +371,15 @@ def generate_data_row(
values.append(value)

cell_value = field.value % tuple(values)
if field.type == "int" and cell_value.isdigit():
cell_value = int(cell_value)

if is_template and cell_value in [None, ""]:
# Assume string type for empty values in template and
# place a placeholder for xlsx-streaming package to infer cell type from
cell_value = "placeholder value"
# Place a placeholder for xlsx-streaming package to infer cell type from
if field.type == "int":
cell_value = 0 # Integer placeholder
else:
cell_value = "placeholder value" # String placeholder

result.append(cell_value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ msgstr ""
msgid "Työtunnit"
msgstr ""

msgid "Maksettu palkka"
msgid "Maksettu palkka (€)"
msgstr ""

msgid "Summa (€)"
msgstr ""

msgid "Muut edut"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ msgstr ""
msgid "Työtunnit"
msgstr ""

msgid "Maksettu palkka"
msgid "Maksettu palkka (€)"
msgstr ""

msgid "Summa (€)"
msgstr ""

msgid "Muut edut"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ msgstr ""
msgid "Työtunnit"
msgstr ""

msgid "Maksettu palkka"
msgid "Maksettu palkka (€)"
msgstr ""

msgid "Summa (€)"
msgstr ""

msgid "Muut edut"
Expand Down
18 changes: 9 additions & 9 deletions backend/kesaseteli/applications/tests/test_excel_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def employer_summer_voucher_sorting_key(voucher: EmployerSummerVoucher):
output_column.value
) == salary_paid
elif excel_field.title == SUM_FIELD_TITLE:
assert output_column.value == str(voucher.value_in_euros)
assert output_column.value == voucher.value_in_euros
elif excel_field.model_fields == ["attachments"]:
expected_attachment_uri = get_attachment_uri(
voucher, excel_field, voucher.attachments, response.wsgi_request
Expand Down Expand Up @@ -360,19 +360,19 @@ def employer_summer_voucher_sorting_key(voucher: EmployerSummerVoucher):
@pytest.mark.parametrize(
"employer_summer_voucher_creation_date,sum_field_value",
[
(date(2021, 6, 1), "325"),
(date(2022, 6, 1), "325"),
(date(2023, 6, 1), "325"),
(date(2024, 1, 1), "325"),
(date(2024, 5, 31), "325"),
(date(2024, 6, 1), "350"),
(date(2024, 12, 31), "350"),
(date(2021, 6, 1), 325),
(date(2022, 6, 1), 325),
(date(2023, 6, 1), 325),
(date(2024, 1, 1), 325),
(date(2024, 5, 31), 325),
(date(2024, 6, 1), 350),
(date(2024, 12, 31), 350),
],
)
def test_excel_view_download_sum_field_value( # noqa: C901
staff_client,
employer_summer_voucher_creation_date: date,
sum_field_value: str,
sum_field_value: int,
):
with freeze_time(employer_summer_voucher_creation_date):
EmployerSummerVoucherFactory(
Expand Down

0 comments on commit 401f815

Please sign in to comment.