Skip to content

Commit

Permalink
Migrate opening hours models to the new app
Browse files Browse the repository at this point in the history
  • Loading branch information
matti-lamppu committed Sep 27, 2024
1 parent 660ac9b commit 876a5a1
Show file tree
Hide file tree
Showing 86 changed files with 792 additions and 532 deletions.
5 changes: 2 additions & 3 deletions actions/recurring_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import TYPE_CHECKING, Any, TypedDict

from common.date_utils import DEFAULT_TIMEZONE, combine, get_periods_between
from opening_hours.utils.time_span_element import TimeSpanElement
from reservations.enums import RejectionReadinessChoice, ReservationTypeChoice, ReservationTypeStaffChoice
from reservations.models import (
AffectingTimeSpan,
Expand All @@ -15,16 +14,16 @@
Reservation,
ReservationPurpose,
)
from tilavarauspalvelu.utils.opening_hours.time_span_element import TimeSpanElement

if TYPE_CHECKING:
from collections.abc import Collection, Iterable

from django.db import models

from applications.models import City
from opening_hours.models import ReservableTimeSpan
from reservations.enums import CustomerTypeChoice, ReservationStateChoice
from tilavarauspalvelu.models import User
from tilavarauspalvelu.models import ReservableTimeSpan, User


class ReservationPeriod(TypedDict):
Expand Down
10 changes: 5 additions & 5 deletions actions/reservation_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from typing import TYPE_CHECKING, Any

from common.date_utils import DEFAULT_TIMEZONE, time_as_timedelta
from opening_hours.errors import HaukiAPIError
from opening_hours.models import OriginHaukiResource, ReservableTimeSpan
from opening_hours.utils.hauki_api_client import HaukiAPIClient
from opening_hours.utils.hauki_api_types import HaukiAPIResource, HaukiTranslatedField
from reservation_units.enums import ReservationStartInterval
from tilavarauspalvelu.exceptions import HaukiAPIError
from tilavarauspalvelu.models import OriginHaukiResource
from tilavarauspalvelu.utils.opening_hours.hauki_api_client import HaukiAPIClient
from tilavarauspalvelu.utils.opening_hours.hauki_api_types import HaukiAPIResource, HaukiTranslatedField
from utils.external_service.errors import ExternalServiceError

if TYPE_CHECKING:
Expand All @@ -18,7 +18,7 @@

from reservation_units.models import ReservationUnit
from reservations.models import Reservation
from tilavarauspalvelu.models import Building, Location
from tilavarauspalvelu.models import Building, Location, ReservableTimeSpan

__all__ = [
"ReservationUnitActions",
Expand Down
6 changes: 3 additions & 3 deletions applications/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
from common.date_utils import local_end_of_day, local_start_of_day
from common.utils import translate_for_user
from config.celery import app
from opening_hours.enums import HaukiResourceState
from opening_hours.utils.hauki_api_client import HaukiAPIClient
from opening_hours.utils.time_span_element import TimeSpanElement
from reservations.enums import CustomerTypeChoice, ReservationStateChoice, ReservationTypeChoice
from reservations.models import RecurringReservation
from reservations.tasks import create_or_update_reservation_statistics, update_affecting_time_spans_task
from tilavarauspalvelu.enums import HaukiResourceState
from tilavarauspalvelu.utils.opening_hours.hauki_api_client import HaukiAPIClient
from tilavarauspalvelu.utils.opening_hours.time_span_element import TimeSpanElement
from utils.sentry import SentryLogger


Expand Down
7 changes: 7 additions & 0 deletions common/date_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,10 @@ def get_periods_between(

for delta in range(0, (end_date - start_date).days + 1, interval):
yield start_datetime + datetime.timedelta(days=delta), end_datetime + datetime.timedelta(days=delta)


def normalize_as_datetime(value: datetime.date | datetime.datetime, *, timedelta_days: int = 0) -> datetime.datetime:
if isinstance(value, datetime.datetime):
return value
# Convert dates to datetimes to include timezone information
return combine(value, datetime.time.min, tzinfo=DEFAULT_TIMEZONE) + datetime.timedelta(days=timedelta_days)
11 changes: 9 additions & 2 deletions common/management/commands/data_creation/create_caisa.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from datetime import date, timedelta

from opening_hours.models import OriginHaukiResource
from reservation_units.enums import (
AuthenticationType,
PriceUnit,
Expand All @@ -22,7 +21,15 @@
)
from reservations.models import ReservationMetadataSet
from tilavarauspalvelu.enums import TermsOfUseTypeChoices
from tilavarauspalvelu.models import PaymentAccounting, PaymentMerchant, PaymentProduct, Space, TermsOfUse, Unit
from tilavarauspalvelu.models import (
OriginHaukiResource,
PaymentAccounting,
PaymentMerchant,
PaymentProduct,
Space,
TermsOfUse,
Unit,
)

from .utils import SetName, with_logs

Expand Down
2 changes: 1 addition & 1 deletion common/management/commands/data_creation/create_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from django.utils.timezone import localtime
from django_celery_beat.models import CrontabSchedule, PeriodicTask

from common.date_utils import DEFAULT_TIMEZONE
from common.enums import BannerNotificationLevel, BannerNotificationTarget
from common.models import BannerNotification
from opening_hours.models import DEFAULT_TIMEZONE
from reservations.tasks import prune_reservations_task, update_affecting_time_spans_task, update_expired_orders_task

from .utils import faker_en, faker_fi, faker_sv, with_logs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from decimal import Decimal
from itertools import cycle

from opening_hours.models import OriginHaukiResource, ReservableTimeSpan
from reservation_units.enums import (
AuthenticationType,
PriceUnit,
Expand All @@ -29,7 +28,7 @@
)
from reservations.models import ReservationMetadataSet
from tilavarauspalvelu.enums import TermsOfUseTypeChoices
from tilavarauspalvelu.models import Resource, Service, TermsOfUse, Unit
from tilavarauspalvelu.models import OriginHaukiResource, ReservableTimeSpan, Resource, Service, TermsOfUse, Unit

from .create_seasonal_booking import _create_application_round_time_slots
from .utils import (
Expand Down
200 changes: 100 additions & 100 deletions locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1346,106 +1346,6 @@ msgstr "Englanti"
msgid "Swedish"
msgstr "Ruotsi"

#: opening_hours/admin/origin_hauki_resource.py
msgid ""
"OriginHaukiResources with this specific hash never have any opening hours."
msgstr ""
"OriginHaukiResources, joilla on tämä tietty tarkiste, eivät koskaan sisällä "
"aukioloaikoja."

#: opening_hours/admin/origin_hauki_resource.py
msgid "ID of the resource in Hauki."
msgstr "Resurssin tunniste Aukiolosovelluksesta."

#: opening_hours/admin/origin_hauki_resource.py
msgid ""
"Hash of the opening hours. Used to determine if the opening hours have "
"changed."
msgstr ""
"Aukioloaikojen tarkiste. Käytetään määrittämään, ovatko aukioloajat "
"muuttuneet."

#: opening_hours/admin/origin_hauki_resource.py
msgid ""
"All opening hours have been fetched from Hauki up until this date. Opening "
"hours are fetched until the last day of the month two years from now."
msgstr ""
"Kaikki aukioloajat on haettu Aukiolosovelluksesta tähän päivämäärään asti. "
"Aukioloajat haetaan kaksi vuotta eteenpäin."

#: opening_hours/admin/origin_hauki_resource.py
msgid "Reservable Time Spans updated."
msgstr "Varattavat aikavälit päivitetty."

#: opening_hours/enums.py
msgctxt "HaukiResourceState"
msgid "Open"
msgstr "Auki"

#: opening_hours/enums.py
msgctxt "HaukiResourceState"
msgid "Closed"
msgstr "Suljettu"

#: opening_hours/enums.py
msgctxt "HaukiResourceState"
msgid "Undefined"
msgstr "Määrittelemätön"

#: opening_hours/enums.py
msgctxt "HaukiResourceState"
msgid "Self service"
msgstr "Itsepalvelu"

#: opening_hours/enums.py
msgctxt "HaukiResourceState"
msgid "With key"
msgstr "Avaimella"

#: opening_hours/enums.py
msgctxt "HaukiResourceState"
msgid "With reservation"
msgstr "Varauksella"

#: opening_hours/enums.py
msgctxt "HaukiResourceState"
msgid "Open and reservable"
msgstr "Auki ja varattavissa"

#: opening_hours/enums.py
msgctxt "HaukiResourceState"
msgid "With key and reservation"
msgstr "Avaimella ja varauksella"

#: opening_hours/enums.py
msgctxt "HaukiResourceState"
msgid "Enter only"
msgstr "Vain sisäänkäynti"

#: opening_hours/enums.py
msgctxt "HaukiResourceState"
msgid "Exit only"
msgstr "Vain uloskäynti"

#: opening_hours/enums.py
msgctxt "HaukiResourceState"
msgid "Weather permitting"
msgstr "Sään salliessa"

#: opening_hours/enums.py
msgctxt "HaukiResourceState"
msgid "Not in use"
msgstr "Ei vuoroa käytössä"

#: opening_hours/enums.py
msgctxt "HaukiResourceState"
msgid "Maintenance"
msgstr "Siivoustauko/huoltotauko"

#: opening_hours/models.py
msgid "`start_datetime` must be before `end_datetime`."
msgstr "`start_datetime` täytyy olla ennen `end_datetime`."

#: reservation_units/admin/reservation_unit/admin.py
msgid "Search by ID, name, unit name, or service sector name"
msgstr "Etsi ID:llä, nimellä, toimipisteen nimellä tai palvelualueen nimellä"
Expand Down Expand Up @@ -2804,6 +2704,37 @@ msgstr "Testisähköposti '%s' lähetetty onnistuneesti."
msgid "Search by username, email, first name or last name"
msgstr "Etsi käyttäjänimellä, sähköpostilla, etu- tai sukunimellä"

#: tilavarauspalvelu/admin/origin_hauki_resource/admin.py
msgid ""
"OriginHaukiResources with this specific hash never have any opening hours."
msgstr ""
"OriginHaukiResources, joilla on tämä tietty tarkiste, eivät koskaan sisällä "
"aukioloaikoja."

#: tilavarauspalvelu/admin/origin_hauki_resource/admin.py
msgid "ID of the resource in Hauki."
msgstr "Resurssin tunniste Aukiolosovelluksesta."

#: tilavarauspalvelu/admin/origin_hauki_resource/admin.py
msgid ""
"Hash of the opening hours. Used to determine if the opening hours have "
"changed."
msgstr ""
"Aukioloaikojen tarkiste. Käytetään määrittämään, ovatko aukioloajat "
"muuttuneet."

#: tilavarauspalvelu/admin/origin_hauki_resource/admin.py
msgid ""
"All opening hours have been fetched from Hauki up until this date. Opening "
"hours are fetched until the last day of the month two years from now."
msgstr ""
"Kaikki aukioloajat on haettu Aukiolosovelluksesta tähän päivämäärään asti. "
"Aukioloajat haetaan kaksi vuotta eteenpäin."

#: tilavarauspalvelu/admin/origin_hauki_resource/admin.py
msgid "Reservable Time Spans updated."
msgstr "Varattavat aikavälit päivitetty."

#: tilavarauspalvelu/admin/payment_merchant/admin.py
msgid "The Paytrail Merchant ID should be a six-digit number."
msgstr "Kaupan paytrail-tunnuksen tulisi olla kuusinumeroinen."
Expand Down Expand Up @@ -3061,6 +2992,71 @@ msgstr "Varaaja"
msgid "Notification manager"
msgstr "Ilmoituksen hallitsija."

#: tilavarauspalvelu/enums.py
msgctxt "HaukiResourceState"
msgid "Open"
msgstr "Auki"

#: tilavarauspalvelu/enums.py
msgctxt "HaukiResourceState"
msgid "Closed"
msgstr "Suljettu"

#: tilavarauspalvelu/enums.py
msgctxt "HaukiResourceState"
msgid "Undefined"
msgstr "Määrittelemätön"

#: tilavarauspalvelu/enums.py
msgctxt "HaukiResourceState"
msgid "Self service"
msgstr "Itsepalvelu"

#: tilavarauspalvelu/enums.py
msgctxt "HaukiResourceState"
msgid "With key"
msgstr "Avaimella"

#: tilavarauspalvelu/enums.py
msgctxt "HaukiResourceState"
msgid "With reservation"
msgstr "Varauksella"

#: tilavarauspalvelu/enums.py
msgctxt "HaukiResourceState"
msgid "Open and reservable"
msgstr "Auki ja varattavissa"

#: tilavarauspalvelu/enums.py
msgctxt "HaukiResourceState"
msgid "With key and reservation"
msgstr "Avaimella ja varauksella"

#: tilavarauspalvelu/enums.py
msgctxt "HaukiResourceState"
msgid "Enter only"
msgstr "Vain sisäänkäynti"

#: tilavarauspalvelu/enums.py
msgctxt "HaukiResourceState"
msgid "Exit only"
msgstr "Vain uloskäynti"

#: tilavarauspalvelu/enums.py
msgctxt "HaukiResourceState"
msgid "Weather permitting"
msgstr "Sään salliessa"

#: tilavarauspalvelu/enums.py
msgctxt "HaukiResourceState"
msgid "Not in use"
msgstr "Ei vuoroa käytössä"

#: tilavarauspalvelu/enums.py
msgctxt "HaukiResourceState"
msgid "Maintenance"
msgstr "Siivoustauko/huoltotauko"

#: tilavarauspalvelu/models/email_template/model.py
msgid "Email type"
msgstr "Sähköpostin tyyppi"
Expand Down Expand Up @@ -3125,6 +3121,10 @@ msgstr "Täytyy olla suurempi kuin 0"
msgid "Must be the sum of net and vat amounts"
msgstr "Täytyy olla netto- ja ALV-määrien summa"

#: tilavarauspalvelu/models/reservable_time_span/model.py
msgid "`start_datetime` must be before `end_datetime`."
msgstr "`start_datetime` täytyy olla ennen `end_datetime`."

#: tilavarauspalvelu/models/terms_of_use/model.py
msgctxt "singular"
msgid "terms of use"
Expand Down
Loading

0 comments on commit 876a5a1

Please sign in to comment.