From e527894790a4261720e9c4eb41503ddcdcea4a0f Mon Sep 17 00:00:00 2001 From: Matti Lamppu Date: Wed, 22 Jan 2025 08:05:14 +0200 Subject: [PATCH] Remove reservee language from reservations Use user.preferred_language instead --- locale/fi/LC_MESSAGES/django.po | 8 -------- locale/sv/LC_MESSAGES/django.po | 8 -------- tests/factories/reservation.py | 2 -- .../test_create_order_params.py | 6 +++--- .../test_verkkokauppa/test_helpers.py | 17 +++++++---------- .../test_create_series.py | 2 -- .../test_update_series.py | 2 -- .../test_reservation/test_confirm.py | 10 +++++----- .../test_email/test_find_language.py | 17 ++--------------- .../test_email/test_find_recipients.py | 2 -- .../test_models/test_reservation_statistics.py | 3 ++- .../test_reservation_querysets.py | 3 +-- tilavarauspalvelu/admin/reservation/admin.py | 1 - tilavarauspalvelu/admin/reservation/form.py | 2 -- .../types/recurring_reservation/serializers.py | 3 --- .../staff_reservation_modify_serializers.py | 1 - tilavarauspalvelu/enums.py | 5 ----- .../integrations/email/find_language.py | 2 -- .../integrations/verkkokauppa/helpers.py | 8 ++++---- .../data_creation/create_reservations.py | 3 +-- ...064_remove_reservation_reservee_language.py | 18 ++++++++++++++++++ .../models/recurring_reservation/actions.py | 1 - .../models/reservation/actions.py | 6 +----- tilavarauspalvelu/models/reservation/model.py | 13 +------------ .../models/reservation_statistic/model.py | 2 +- 25 files changed, 46 insertions(+), 99 deletions(-) create mode 100644 tilavarauspalvelu/migrations/0064_remove_reservation_reservee_language.py diff --git a/locale/fi/LC_MESSAGES/django.po b/locale/fi/LC_MESSAGES/django.po index 4323eac6c..cfc1b306c 100644 --- a/locale/fi/LC_MESSAGES/django.po +++ b/locale/fi/LC_MESSAGES/django.po @@ -1428,10 +1428,6 @@ msgstr "Varaajan postinumero" msgid "Reservee is an unregistered association" msgstr "Varaaja on rekisteröimätön yhdistys" -#: tilavarauspalvelu/admin/reservation/form.py -msgid "Preferred language of reservee" -msgstr "Varaajan kieli" - #: tilavarauspalvelu/admin/reservation/form.py msgid "Type of reservee" msgstr "Varaajan tyyppi" @@ -1610,10 +1606,6 @@ msgstr "Varaajan kaupunki" msgid "Reservee's zip code" msgstr "Varaajan postinumero" -#: tilavarauspalvelu/admin/reservation/form.py -msgid "Reservee's preferred language" -msgstr "Varaajan suosima kieli" - #: tilavarauspalvelu/admin/reservation/form.py msgid "User who made the reservation" msgstr "Varauksen tehnyt käyttäjä" diff --git a/locale/sv/LC_MESSAGES/django.po b/locale/sv/LC_MESSAGES/django.po index 2b46bc938..70850dbd7 100644 --- a/locale/sv/LC_MESSAGES/django.po +++ b/locale/sv/LC_MESSAGES/django.po @@ -1384,10 +1384,6 @@ msgstr "" msgid "Reservee is an unregistered association" msgstr "" -#: tilavarauspalvelu/admin/reservation/form.py -msgid "Preferred language of reservee" -msgstr "" - #: tilavarauspalvelu/admin/reservation/form.py msgid "Type of reservee" msgstr "" @@ -1566,10 +1562,6 @@ msgstr "" msgid "Reservee's zip code" msgstr "" -#: tilavarauspalvelu/admin/reservation/form.py -msgid "Reservee's preferred language" -msgstr "" - #: tilavarauspalvelu/admin/reservation/form.py msgid "User who made the reservation" msgstr "" diff --git a/tests/factories/reservation.py b/tests/factories/reservation.py index f98b31c0c..c1b8ff49b 100644 --- a/tests/factories/reservation.py +++ b/tests/factories/reservation.py @@ -83,7 +83,6 @@ class Meta: reservee_address_zip = FakerFI("postcode") reservee_is_unregistered_association = False reservee_used_ad_login = False - reservee_language = LazyAttribute(lambda i: i.user.get_preferred_language()) reservee_type = CustomerTypeChoice.INDIVIDUAL # Billing information @@ -309,7 +308,6 @@ def for_user(self, user: User) -> Self: self.kwargs["reservee_first_name"] = user.first_name self.kwargs["reservee_last_name"] = user.last_name self.kwargs["reservee_email"] = user.email - self.kwargs["reservee_language"] = user.get_preferred_language() return self def for_reservation_unit(self, reservation_unit: ReservationUnit) -> Self: diff --git a/tests/test_external_services/test_verkkokauppa/test_create_order_params.py b/tests/test_external_services/test_verkkokauppa/test_create_order_params.py index 1cbb49ef8..9287821a9 100644 --- a/tests/test_external_services/test_verkkokauppa/test_create_order_params.py +++ b/tests/test_external_services/test_verkkokauppa/test_create_order_params.py @@ -28,6 +28,7 @@ def test_get_verkkokauppa_order_params__to_json(): email="test@localhost", first_name="First", last_name="Last", + preferred_language="fi", ) reservation = ReservationFactory.create( reservation_units=[reservation_unit], @@ -39,7 +40,6 @@ def test_get_verkkokauppa_order_params__to_json(): reservee_last_name="Lastname", reservee_email="test@example.com", reservee_phone="+358 50 123 4567", - reservee_language="fi", ) order_params = get_verkkokauppa_order_params(reservation) @@ -47,7 +47,7 @@ def test_get_verkkokauppa_order_params__to_json(): assert json["namespace"] == settings.VERKKOKAUPPA_NAMESPACE assert json["user"] == str(reservation.user.uuid) - assert json["language"] == reservation.reservee_language or "fi" + assert json["language"] == reservation.user.get_preferred_language() assert json["priceNet"] == "10.12" assert json["priceVat"] == "2.43" assert json["priceTotal"] == "12.55" @@ -93,6 +93,7 @@ def test_get_verkkokauppa_order_params__to_json__meta_label_language_support(): email="test@localhost", first_name="First", last_name="Name", + preferred_language="en", ) reservation = ReservationFactory.create( reservation_units=[reservation_unit], @@ -104,7 +105,6 @@ def test_get_verkkokauppa_order_params__to_json__meta_label_language_support(): reservee_last_name="Lastname", reservee_email="test@example.com", reservee_phone="+358 50 123 4567", - reservee_language="en", ) order_params = get_verkkokauppa_order_params(reservation) diff --git a/tests/test_external_services/test_verkkokauppa/test_helpers.py b/tests/test_external_services/test_verkkokauppa/test_helpers.py index 7582e6e46..3ffc9eb67 100644 --- a/tests/test_external_services/test_verkkokauppa/test_helpers.py +++ b/tests/test_external_services/test_verkkokauppa/test_helpers.py @@ -6,7 +6,7 @@ from django.utils.timezone import get_default_timezone from freezegun import freeze_time -from tilavarauspalvelu.enums import CustomerTypeChoice, Language +from tilavarauspalvelu.enums import CustomerTypeChoice from tilavarauspalvelu.integrations.verkkokauppa.exceptions import UnsupportedMetaKeyError from tilavarauspalvelu.integrations.verkkokauppa.helpers import ( get_formatted_reservation_time, @@ -14,7 +14,7 @@ get_verkkokauppa_order_params, ) -from tests.factories import PaymentProductFactory, ReservationFactory, ReservationUnitFactory, UserFactory +from tests.factories import PaymentProductFactory, ReservationFactory, ReservationUnitFactory # Applied to all tests pytestmark = [ @@ -35,13 +35,12 @@ def test_get_formatted_reservation_time(language, result): begin = datetime.datetime.now().astimezone(tz=get_default_timezone()) end = begin + datetime.timedelta(hours=2) - reservation = ReservationFactory.create(begin=begin, end=end, reservee_language=language) + reservation = ReservationFactory.create(begin=begin, end=end, user__preferred_language=language) date = get_formatted_reservation_time(reservation) assert date == result def test_get_verkkokauppa_order_params__respect_reservee_language(): - user = UserFactory.create() payment_product = PaymentProductFactory.create() runit = ReservationUnitFactory.create( payment_product=payment_product, @@ -52,25 +51,23 @@ def test_get_verkkokauppa_order_params__respect_reservee_language(): reservation_en = ReservationFactory.create( reservation_units=[runit], - user=user, + user__preferred_language="en", reservee_type=CustomerTypeChoice.INDIVIDUAL, - reservee_language=Language.EN.value, ) order_params = get_verkkokauppa_order_params(reservation_en) assert order_params.items[0].product_name == "Name" reservation_sv = ReservationFactory.create( reservation_units=[runit], - user=user, + user__preferred_language="sv", reservee_type=CustomerTypeChoice.INDIVIDUAL, - reservee_language=Language.SV.value, ) order_params = get_verkkokauppa_order_params(reservation_sv) assert order_params.items[0].product_name == "Namn" def test_get_meta_label(): - reservation = ReservationFactory.create(reservee_language=Language.FI.value) + reservation = ReservationFactory.create(user__preferred_language="fi") period_label = get_meta_label("reservationPeriod", reservation) assert period_label == "Varausaika" @@ -80,7 +77,7 @@ def test_get_meta_label(): def test_get_meta_label__raises_exception_with_unsupported_key(): - reservation = ReservationFactory.create(reservee_language=Language.FI.value) + reservation = ReservationFactory.create(user__preferred_language="fi") with pytest.raises(UnsupportedMetaKeyError) as err: get_meta_label("unsupported", reservation) diff --git a/tests/test_graphql_api/test_recurring_reservation/test_create_series.py b/tests/test_graphql_api/test_recurring_reservation/test_create_series.py index 41f2eedf7..27d30d819 100644 --- a/tests/test_graphql_api/test_recurring_reservation/test_create_series.py +++ b/tests/test_graphql_api/test_recurring_reservation/test_create_series.py @@ -110,7 +110,6 @@ def test_recurring_reservations__create_series__reservation_details(graphql): data["reservationDetails"]["reserveeAddressCity"] = "city" data["reservationDetails"]["reserveeAddressZip"] = "cip" data["reservationDetails"]["reserveeIsUnregisteredAssociation"] = False - data["reservationDetails"]["reserveeLanguage"] = "FI" data["reservationDetails"]["reserveeType"] = CustomerTypeChoice.BUSINESS.upper() data["reservationDetails"]["billingFirstName"] = "Bill" data["reservationDetails"]["billingLastName"] = "Admin" @@ -157,7 +156,6 @@ def test_recurring_reservations__create_series__reservation_details(graphql): assert reservations[0].reservee_address_city == "city" assert reservations[0].reservee_address_zip == "cip" assert reservations[0].reservee_is_unregistered_association is False - assert reservations[0].reservee_language == "fi" assert reservations[0].reservee_type == CustomerTypeChoice.BUSINESS assert reservations[0].billing_first_name == "Bill" assert reservations[0].billing_last_name == "Admin" diff --git a/tests/test_graphql_api/test_recurring_reservation/test_update_series.py b/tests/test_graphql_api/test_recurring_reservation/test_update_series.py index 3e5f30830..1b89a7dc4 100644 --- a/tests/test_graphql_api/test_recurring_reservation/test_update_series.py +++ b/tests/test_graphql_api/test_recurring_reservation/test_update_series.py @@ -66,7 +66,6 @@ def test_recurring_reservations__update_series(graphql): "reserveeAddressCity": "city", "reserveeAddressZip": "cip", "reserveeIsUnregisteredAssociation": False, - "reserveeLanguage": "FI", "reserveeType": CustomerTypeChoice.BUSINESS.upper(), "billingFirstName": "Bill", "billingLastName": "Admin", @@ -108,7 +107,6 @@ def test_recurring_reservations__update_series(graphql): assert reservation.reservee_address_city == "city" assert reservation.reservee_address_zip == "cip" assert reservation.reservee_is_unregistered_association is False - assert reservation.reservee_language == "fi" assert reservation.reservee_type == CustomerTypeChoice.BUSINESS assert reservation.billing_first_name == "Bill" assert reservation.billing_last_name == "Admin" diff --git a/tests/test_graphql_api/test_reservation/test_confirm.py b/tests/test_graphql_api/test_reservation/test_confirm.py index 87d4b86cf..289c0cb26 100644 --- a/tests/test_graphql_api/test_reservation/test_confirm.py +++ b/tests/test_graphql_api/test_reservation/test_confirm.py @@ -227,7 +227,7 @@ def test_reservation__confirm__does_not_create_order_when_handling_is_required(g def test_reservation__confirm__creates_local_order_when_payment_type_is_on_site(graphql): reservation = ReservationFactory.create_for_confirmation( reservation_units__payment_types__code=PaymentType.ON_SITE, - reservee_language="fi", + user__preferred_language="fi", ) graphql.login_with_superuser() @@ -243,7 +243,7 @@ def test_reservation__confirm__creates_local_order_when_payment_type_is_on_site( assert len(orders) == 1 assert orders[0].payment_type == PaymentType.ON_SITE assert orders[0].status == OrderStatus.PAID_MANUALLY - assert orders[0].language == reservation.reservee_language + assert orders[0].language == reservation.user.preferred_language assert orders[0].reservation == reservation assert VerkkokauppaAPIClient.create_order.called is False @@ -253,7 +253,7 @@ def test_reservation__confirm__creates_local_order_when_payment_type_is_on_site( def test_reservation__confirm__calls_verkkokauppa_api_when_payment_type_is_not_on_site(graphql): reservation = ReservationFactory.create_for_confirmation( reservation_units__payment_types__code=PaymentType.INVOICE, - reservee_language="fi", + user__preferred_language="fi", ) order = OrderFactory.create() @@ -272,7 +272,7 @@ def test_reservation__confirm__calls_verkkokauppa_api_when_payment_type_is_not_o assert len(orders) == 1 assert orders[0].payment_type == PaymentType.INVOICE assert orders[0].status == OrderStatus.DRAFT - assert orders[0].language == reservation.reservee_language + assert orders[0].language == reservation.user.preferred_language assert orders[0].reservation == reservation assert orders[0].remote_id == order.order_id assert orders[0].checkout_url == order.checkout_url @@ -286,7 +286,7 @@ def test_reservation__confirm__calls_verkkokauppa_api_when_payment_type_is_not_o def test_reservation__confirm__does_not_save_when_api_call_fails(graphql): reservation = ReservationFactory.create_for_confirmation( reservation_units__payment_types__code=PaymentType.INVOICE, - reservee_language="fi", + user__preferred_language="fi", ) graphql.login_with_superuser() diff --git a/tests/test_integrations/test_email/test_find_language.py b/tests/test_integrations/test_email/test_find_language.py index 60c023761..b5d8f7cac 100644 --- a/tests/test_integrations/test_email/test_find_language.py +++ b/tests/test_integrations/test_email/test_find_language.py @@ -24,7 +24,7 @@ def test_get_application_email_language(preferred_language): assert lang == preferred_language -def test_get_application_email_language__invalid_preferred_language(): +def test_get_application_email_language__invalid_language(): application = ApplicationFactory.create(user__preferred_language="uk") lang = get_application_email_language(application) @@ -36,7 +36,6 @@ def test_get_application_email_language__invalid_preferred_language(): def test_get_reservation_email_language(preferred_language): reservation = ReservationFactory.create( user__preferred_language=preferred_language, - reservee_language="", ) lang = get_reservation_email_language(reservation) @@ -44,21 +43,9 @@ def test_get_reservation_email_language(preferred_language): assert lang == preferred_language -def test_get_reservation_email_language__use_reservee_language(): - reservation = ReservationFactory.create( - user__preferred_language="", - reservee_language=Language.EN.value, - ) - - lang = get_reservation_email_language(reservation) - - assert lang == Language.EN.value - - -def test_get_reservation_email_language__invalid_languages(): +def test_get_reservation_email_language__invalid_language(): reservation = ReservationFactory.create( user__preferred_language="uk", - reservee_language="es", ) lang = get_reservation_email_language(reservation) diff --git a/tests/test_integrations/test_email/test_find_recipients.py b/tests/test_integrations/test_email/test_find_recipients.py index bfb8facd1..0179d5c48 100644 --- a/tests/test_integrations/test_email/test_find_recipients.py +++ b/tests/test_integrations/test_email/test_find_recipients.py @@ -68,7 +68,6 @@ def test_get_reservation_email_recipients__no_user(): reservation = ReservationFactory.create( user=None, reservee_email="reservee@example.com", - reservee_language=Language.EN.value, ) result = get_reservation_email_recipients(reservation) @@ -79,7 +78,6 @@ def test_get_reservation_email_recipients__no_reservee_email_or_user(): reservation = ReservationFactory.create( user=None, reservee_email="", - reservee_language=Language.EN.value, ) result = get_reservation_email_recipients(reservation) diff --git a/tests/test_models/test_reservation_statistics.py b/tests/test_models/test_reservation_statistics.py index 8ca4f12a4..1f75de2b1 100644 --- a/tests/test_models/test_reservation_statistics.py +++ b/tests/test_models/test_reservation_statistics.py @@ -55,6 +55,7 @@ def test_statistics__create__reservation_creation_creates_statistics(settings): tax_percentage_value=24, unit_price=10, working_memo="its like that", + user__preferred_language="fi", ) reservation_unit = reservation.reservation_units.first() @@ -107,7 +108,7 @@ def test_statistics__create__reservation_creation_creates_statistics(settings): assert stat.reservee_address_zip == "" assert stat.reservee_id == "" assert stat.reservee_is_unregistered_association == reservation.reservee_is_unregistered_association - assert stat.reservee_language == reservation.reservee_language + assert stat.reservee_language == reservation.user.preferred_language assert stat.reservee_organisation_name == "" assert stat.reservee_type == reservation.reservee_type assert stat.reservee_uuid == str(reservation.user.tvp_uuid) diff --git a/tests/test_querysets/test_reservation_querysets.py b/tests/test_querysets/test_reservation_querysets.py index 4548db1dc..a12495a68 100644 --- a/tests/test_querysets/test_reservation_querysets.py +++ b/tests/test_querysets/test_reservation_querysets.py @@ -5,7 +5,7 @@ import pytest -from tilavarauspalvelu.enums import Language, ReservationStateChoice, ReservationTypeChoice +from tilavarauspalvelu.enums import ReservationStateChoice, ReservationTypeChoice from tilavarauspalvelu.integrations.opening_hours.time_span_element import TimeSpanElement from tilavarauspalvelu.models import AffectingTimeSpan, Reservation, ReservationUnit, ReservationUnitHierarchy from utils.date_utils import DEFAULT_TIMEZONE, local_date @@ -40,7 +40,6 @@ def _create_test_reservations_for_all_reservation_units() -> None: end=_datetime(minute=0), reservation_units=[reservation_unit], user=None, - reservee_language=Language.FI.value, state=ReservationStateChoice.CREATED, type=ReservationTypeChoice.NORMAL, ) diff --git a/tilavarauspalvelu/admin/reservation/admin.py b/tilavarauspalvelu/admin/reservation/admin.py index 6d5ca290d..36a1e03f4 100644 --- a/tilavarauspalvelu/admin/reservation/admin.py +++ b/tilavarauspalvelu/admin/reservation/admin.py @@ -159,7 +159,6 @@ class ReservationAdmin(admin.ModelAdmin): "reservee_address_city", "reservee_address_zip", "reservee_is_unregistered_association", - "reservee_language", "reservee_type", ], }, diff --git a/tilavarauspalvelu/admin/reservation/form.py b/tilavarauspalvelu/admin/reservation/form.py index e83f1b9fa..c3f47bf09 100644 --- a/tilavarauspalvelu/admin/reservation/form.py +++ b/tilavarauspalvelu/admin/reservation/form.py @@ -51,7 +51,6 @@ class Meta: "reservee_address_city": _("Reservee address city"), "reservee_address_zip": _("Reservee address zip code"), "reservee_is_unregistered_association": _("Reservee is an unregistered association"), - "reservee_language": _("Preferred language of reservee"), "reservee_type": _("Type of reservee"), # "billing_first_name": _("Billing first name"), @@ -111,7 +110,6 @@ class Meta: "reservee_address_city": _("Reservee's city"), "reservee_address_zip": _("Reservee's zip code"), "reservee_is_unregistered_association": _("Reservee is an unregistered association"), - "reservee_language": _("Reservee's preferred language"), "reservee_type": _("Type of reservee"), # "billing_first_name": _("Billing first name"), diff --git a/tilavarauspalvelu/api/graphql/types/recurring_reservation/serializers.py b/tilavarauspalvelu/api/graphql/types/recurring_reservation/serializers.py index b95ff57ba..67cd570de 100644 --- a/tilavarauspalvelu/api/graphql/types/recurring_reservation/serializers.py +++ b/tilavarauspalvelu/api/graphql/types/recurring_reservation/serializers.py @@ -78,7 +78,6 @@ class Meta: "reservee_address_city", "reservee_address_zip", "reservee_is_unregistered_association", - "reservee_language", "reservee_type", # "billing_first_name", @@ -277,7 +276,6 @@ class Meta: "reservee_address_city", "reservee_address_zip", "reservee_is_unregistered_association", - "reservee_language", "reservee_type", # "billing_first_name", @@ -567,7 +565,6 @@ def get_reservation_details(self, instance: RecurringReservation) -> Reservation reservee_address_city=next_reservation.reservee_address_city, reservee_address_zip=next_reservation.reservee_address_zip, reservee_is_unregistered_association=next_reservation.reservee_is_unregistered_association, - reservee_language=next_reservation.reservee_language, reservee_type=next_reservation.reservee_type, # billing_first_name=next_reservation.billing_first_name, diff --git a/tilavarauspalvelu/api/graphql/types/reservation/serializers/staff_reservation_modify_serializers.py b/tilavarauspalvelu/api/graphql/types/reservation/serializers/staff_reservation_modify_serializers.py index a58383601..cb5471fb6 100644 --- a/tilavarauspalvelu/api/graphql/types/reservation/serializers/staff_reservation_modify_serializers.py +++ b/tilavarauspalvelu/api/graphql/types/reservation/serializers/staff_reservation_modify_serializers.py @@ -68,7 +68,6 @@ class Meta: "reservee_type", "reservee_id", "reservee_is_unregistered_association", - "reservee_language", # # Billing information "billing_address_city", diff --git a/tilavarauspalvelu/enums.py b/tilavarauspalvelu/enums.py index a5c173a1c..9d4e718f6 100644 --- a/tilavarauspalvelu/enums.py +++ b/tilavarauspalvelu/enums.py @@ -7,7 +7,6 @@ from types import DynamicClassAttribute from typing import Literal -from django.conf import settings from django.db import models from django.utils.functional import classproperty from django.utils.translation import gettext_lazy as _ @@ -16,7 +15,6 @@ from tilavarauspalvelu.typing import permission __all__ = [ - "RESERVEE_LANGUAGE_CHOICES", "AccessType", "ApplicantTypeChoice", "ApplicationRoundReservationCreationStatusChoice", @@ -554,9 +552,6 @@ class ReservationTypeStaffChoice(models.TextChoices): BEHALF = "BEHALF", pgettext_lazy("ReservationTypeStaffChoice", "Behalf") -RESERVEE_LANGUAGE_CHOICES = (*settings.LANGUAGES, ("", "")) - - class RejectionReadinessChoice(models.TextChoices): INTERVAL_NOT_ALLOWED = ( "INTERVAL_NOT_ALLOWED", diff --git a/tilavarauspalvelu/integrations/email/find_language.py b/tilavarauspalvelu/integrations/email/find_language.py index 586c2ba79..39bdab60e 100644 --- a/tilavarauspalvelu/integrations/email/find_language.py +++ b/tilavarauspalvelu/integrations/email/find_language.py @@ -26,6 +26,4 @@ def get_reservation_email_language(reservation: Reservation) -> Lang: """Get email notification language for the given application.""" if getattr(reservation.user, "preferred_language", None) in Language.values: return reservation.user.preferred_language # type: ignore[return-value] - if reservation.reservee_language in Language.values: - return reservation.reservee_language # type: ignore[return-value] return settings.LANGUAGE_CODE diff --git a/tilavarauspalvelu/integrations/verkkokauppa/helpers.py b/tilavarauspalvelu/integrations/verkkokauppa/helpers.py index 0906f314a..492510730 100644 --- a/tilavarauspalvelu/integrations/verkkokauppa/helpers.py +++ b/tilavarauspalvelu/integrations/verkkokauppa/helpers.py @@ -39,7 +39,7 @@ def get_formatted_reservation_time(reservation: Reservation) -> str: begin = reservation.begin.astimezone(DEFAULT_TIMEZONE) end = reservation.end.astimezone(DEFAULT_TIMEZONE) - preferred_language = reservation.reservee_language or "fi" + preferred_language = reservation.user.get_preferred_language() weekday = localized_short_weekday(begin.weekday(), preferred_language) date = f"{begin.day}.{begin.month}.{begin.year}" start_time = begin.strftime("%H:%M") @@ -65,13 +65,13 @@ def get_meta_label(key: str, reservation: Reservation) -> str: msg = f"Invalid meta label key '{key}'" raise UnsupportedMetaKeyError(msg) - preferred_language = reservation.reservee_language or "fi" + preferred_language = reservation.user.get_preferred_language() return labels[key][preferred_language] def get_verkkokauppa_order_params(reservation: Reservation) -> CreateOrderParams: reservation_unit = reservation.reservation_units.first() - preferred_language = getattr(reservation, "reservee_language", "fi") + preferred_language = reservation.user.get_preferred_language() items = [ OrderItemParams( product_id=reservation_unit.payment_product.id, @@ -113,7 +113,7 @@ def get_verkkokauppa_order_params(reservation: Reservation) -> CreateOrderParams return CreateOrderParams( namespace=settings.VERKKOKAUPPA_NAMESPACE, user=reservation.user.uuid, - language=reservation.reservee_language or "fi", + language=reservation.user.get_preferred_language(), items=items, price_net=Decimal(sum(item.row_price_net for item in items)), price_vat=Decimal(sum(item.row_price_vat for item in items)), diff --git a/tilavarauspalvelu/management/commands/data_creation/create_reservations.py b/tilavarauspalvelu/management/commands/data_creation/create_reservations.py index 319981ece..bf34be53c 100644 --- a/tilavarauspalvelu/management/commands/data_creation/create_reservations.py +++ b/tilavarauspalvelu/management/commands/data_creation/create_reservations.py @@ -8,7 +8,6 @@ from tilavarauspalvelu.enums import ( CustomerTypeChoice, - Language, OrderStatus, PaymentType, ReservationKind, @@ -269,7 +268,7 @@ def _create_normal_reservations( def _build_payment_order(reservation: Reservation, payment_types_choices: list[PaymentType]) -> PaymentOrder: payment_order_builder = PaymentOrderBuilder().set( - language=reservation.reservee_language or Language.FI, + language=reservation.user.get_preferred_language(), price_net=reservation.price_net, price_vat=reservation.price_vat_amount, price_total=reservation.price, diff --git a/tilavarauspalvelu/migrations/0064_remove_reservation_reservee_language.py b/tilavarauspalvelu/migrations/0064_remove_reservation_reservee_language.py new file mode 100644 index 000000000..2c84adb32 --- /dev/null +++ b/tilavarauspalvelu/migrations/0064_remove_reservation_reservee_language.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.4 on 2025-01-22 05:49 +from __future__ import annotations + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("tilavarauspalvelu", "0063_clean_newlines_from_rich_text_fields"), + ] + + operations = [ + migrations.RemoveField( + model_name="reservation", + name="reservee_language", + ), + ] diff --git a/tilavarauspalvelu/models/recurring_reservation/actions.py b/tilavarauspalvelu/models/recurring_reservation/actions.py index 3763935c8..ebe5ed8c6 100644 --- a/tilavarauspalvelu/models/recurring_reservation/actions.py +++ b/tilavarauspalvelu/models/recurring_reservation/actions.py @@ -99,7 +99,6 @@ class ReservationDetails(TypedDict, total=False): reservee_address_city: str reservee_address_zip: str reservee_is_unregistered_association: bool - reservee_language: str reservee_type: CustomerTypeChoice billing_first_name: str diff --git a/tilavarauspalvelu/models/reservation/actions.py b/tilavarauspalvelu/models/reservation/actions.py index dcd175db0..ef039fef5 100644 --- a/tilavarauspalvelu/models/reservation/actions.py +++ b/tilavarauspalvelu/models/reservation/actions.py @@ -58,11 +58,7 @@ def get_actual_after_buffer(self) -> datetime.timedelta: return buffer_time_after def to_ical(self) -> bytes: - language: Lang = ( # type: ignore[assignment] - self.reservation.reservee_language - or (self.reservation.user is not None and self.reservation.user.get_preferred_language()) - or settings.LANGUAGE_CODE - ) + language = self.reservation.user.get_preferred_language() cal = Calendar() cal.add(CalendarProperty.VERSION, "2.0") diff --git a/tilavarauspalvelu/models/reservation/model.py b/tilavarauspalvelu/models/reservation/model.py index e43111106..f97884725 100644 --- a/tilavarauspalvelu/models/reservation/model.py +++ b/tilavarauspalvelu/models/reservation/model.py @@ -14,12 +14,7 @@ from lookup_property import lookup_property from config.utils.auditlog_util import AuditLogger -from tilavarauspalvelu.enums import ( - RESERVEE_LANGUAGE_CHOICES, - CustomerTypeChoice, - ReservationStateChoice, - ReservationTypeChoice, -) +from tilavarauspalvelu.enums import CustomerTypeChoice, ReservationStateChoice, ReservationTypeChoice from utils.date_utils import datetime_range_as_string from utils.decimal_utils import round_decimal @@ -101,12 +96,6 @@ class Reservation(SerializableMixin, models.Model): reservee_address_zip: str = models.CharField(max_length=255, blank=True, default="") reservee_is_unregistered_association: bool = models.BooleanField(default=False, blank=True) reservee_used_ad_login: bool = models.BooleanField(default=False, blank=True) - reservee_language: str = models.CharField( - max_length=255, - blank=True, - default="", - choices=RESERVEE_LANGUAGE_CHOICES, - ) reservee_type: str | None = models.CharField( max_length=50, choices=CustomerTypeChoice.choices, diff --git a/tilavarauspalvelu/models/reservation_statistic/model.py b/tilavarauspalvelu/models/reservation_statistic/model.py index 8daaa227a..6816bdea5 100644 --- a/tilavarauspalvelu/models/reservation_statistic/model.py +++ b/tilavarauspalvelu/models/reservation_statistic/model.py @@ -215,7 +215,7 @@ def for_reservation(cls, reservation: Reservation, *, save: bool = True) -> Rese statistic.reservee_address_zip = reservation.reservee_address_zip if by_profile_user else "" statistic.reservee_id = reservation.reservee_id if requires_org_id else "" statistic.reservee_is_unregistered_association = reservation.reservee_is_unregistered_association - statistic.reservee_language = reservation.reservee_language + statistic.reservee_language = reservation.user.get_preferred_language() statistic.reservee_organisation_name = reservation.reservee_organisation_name if requires_org_name else "" statistic.reservee_type = reservation.reservee_type statistic.reservee_used_ad_login = reservation.reservee_used_ad_login