From 401f8157f5b80bf67e1de19fd505e1bfdd754859 Mon Sep 17 00:00:00 2001 From: Kari Salminen Date: Mon, 22 Jan 2024 14:36:42 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20specify=20Excel=20exporter's=20salary?= =?UTF-8?q?=20&=20sum=20fields=20as=20=E2=82=AC,=20cast=20sum=20as=20int?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit related: https://github.com/City-of-Helsinki/yjdh/pull/2745#discussion_r1461439607 refs YJDH-683 --- .../applications/exporters/excel_exporter.py | 21 ++++++++++++------- .../locale/en/LC_MESSAGES/django.po | 5 ++++- .../locale/fi/LC_MESSAGES/django.po | 5 ++++- .../locale/sv/LC_MESSAGES/django.po | 5 ++++- .../applications/tests/test_excel_export.py | 18 ++++++++-------- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/backend/kesaseteli/applications/exporters/excel_exporter.py b/backend/kesaseteli/applications/exporters/excel_exporter.py index 3dd503667f..eb0c5ed384 100644 --- a/backend/kesaseteli/applications/exporters/excel_exporter.py +++ b/backend/kesaseteli/applications/exporters/excel_exporter.py @@ -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 @@ -13,6 +13,8 @@ from applications.models import EmployerSummerVoucher from common.utils import getattr_nested +ExcelFieldType = Literal["int", "str"] + class ExcelField(NamedTuple): title: str @@ -20,6 +22,7 @@ class ExcelField(NamedTuple): model_fields: List[str] width: int background_color: str + type: ExcelFieldType = "str" APPLICATION_LANGUAGE_FIELD_TITLE = _("Hakemuksen kieli") @@ -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") @@ -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"), @@ -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) diff --git a/backend/kesaseteli/applications/locale/en/LC_MESSAGES/django.po b/backend/kesaseteli/applications/locale/en/LC_MESSAGES/django.po index 76f68fc068..ba85c48ede 100644 --- a/backend/kesaseteli/applications/locale/en/LC_MESSAGES/django.po +++ b/backend/kesaseteli/applications/locale/en/LC_MESSAGES/django.po @@ -252,7 +252,10 @@ msgstr "" msgid "Työtunnit" msgstr "" -msgid "Maksettu palkka" +msgid "Maksettu palkka (€)" +msgstr "" + +msgid "Summa (€)" msgstr "" msgid "Muut edut" diff --git a/backend/kesaseteli/applications/locale/fi/LC_MESSAGES/django.po b/backend/kesaseteli/applications/locale/fi/LC_MESSAGES/django.po index 1a5c77e1dc..8243e472e3 100644 --- a/backend/kesaseteli/applications/locale/fi/LC_MESSAGES/django.po +++ b/backend/kesaseteli/applications/locale/fi/LC_MESSAGES/django.po @@ -253,7 +253,10 @@ msgstr "" msgid "Työtunnit" msgstr "" -msgid "Maksettu palkka" +msgid "Maksettu palkka (€)" +msgstr "" + +msgid "Summa (€)" msgstr "" msgid "Muut edut" diff --git a/backend/kesaseteli/applications/locale/sv/LC_MESSAGES/django.po b/backend/kesaseteli/applications/locale/sv/LC_MESSAGES/django.po index 04b2f72bb8..d81b7819c5 100644 --- a/backend/kesaseteli/applications/locale/sv/LC_MESSAGES/django.po +++ b/backend/kesaseteli/applications/locale/sv/LC_MESSAGES/django.po @@ -252,7 +252,10 @@ msgstr "" msgid "Työtunnit" msgstr "" -msgid "Maksettu palkka" +msgid "Maksettu palkka (€)" +msgstr "" + +msgid "Summa (€)" msgstr "" msgid "Muut edut" diff --git a/backend/kesaseteli/applications/tests/test_excel_export.py b/backend/kesaseteli/applications/tests/test_excel_export.py index 64625e3077..8e10c26d01 100644 --- a/backend/kesaseteli/applications/tests/test_excel_export.py +++ b/backend/kesaseteli/applications/tests/test_excel_export.py @@ -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 @@ -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(