diff --git a/tests/test_models/test_reservation_statistics.py b/tests/test_models/test_reservation_statistics.py index 8863ab5ee5..000dc30114 100644 --- a/tests/test_models/test_reservation_statistics.py +++ b/tests/test_models/test_reservation_statistics.py @@ -96,7 +96,7 @@ def test_statistics__create__reservation_creation_creates_statistics(settings): assert stat.purpose_name == reservation.purpose.name assert stat.recurrence_begin_date == recurring.begin_date assert stat.recurrence_end_date == recurring.end_date - assert stat.recurrence_uuid == str(recurring.uuid) + assert stat.recurrence_uuid == str(recurring.ext_id) assert stat.reservation == reservation assert stat.reservation_confirmed_at == reservation.confirmed_at assert stat.reservation_created_at == reservation.created_at diff --git a/tilavarauspalvelu/api/graphql/types/recurring_reservation/types.py b/tilavarauspalvelu/api/graphql/types/recurring_reservation/types.py index 15589a2a49..2c8730b72d 100644 --- a/tilavarauspalvelu/api/graphql/types/recurring_reservation/types.py +++ b/tilavarauspalvelu/api/graphql/types/recurring_reservation/types.py @@ -27,6 +27,7 @@ class Meta: model = RecurringReservation fields = [ "pk", + "ext_id", "user", "age_group", "ability_group", diff --git a/tilavarauspalvelu/api/graphql/types/reservation/types.py b/tilavarauspalvelu/api/graphql/types/reservation/types.py index 8353808925..ffa581a0c1 100644 --- a/tilavarauspalvelu/api/graphql/types/reservation/types.py +++ b/tilavarauspalvelu/api/graphql/types/reservation/types.py @@ -116,6 +116,7 @@ class Meta: fields = [ # "pk", + "ext_id", "name", "description", "num_persons", diff --git a/tilavarauspalvelu/migrations/0041_rename_recurring_reservation_uuid_to_ext_id.py b/tilavarauspalvelu/migrations/0041_rename_recurring_reservation_uuid_to_ext_id.py new file mode 100644 index 0000000000..fb15099053 --- /dev/null +++ b/tilavarauspalvelu/migrations/0041_rename_recurring_reservation_uuid_to_ext_id.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.3 on 2024-11-28 07:23 +from __future__ import annotations + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("tilavarauspalvelu", "0040_alter_reservationstatisticsreservationunit_unit_tprek_id"), + ] + + operations = [ + migrations.RenameField( + model_name="recurringreservation", + old_name="uuid", + new_name="ext_id", + ), + ] diff --git a/tilavarauspalvelu/migrations/0042_add_reservation_uuids.py b/tilavarauspalvelu/migrations/0042_add_reservation_uuids.py new file mode 100644 index 0000000000..c07a3522ed --- /dev/null +++ b/tilavarauspalvelu/migrations/0042_add_reservation_uuids.py @@ -0,0 +1,20 @@ +# Generated by Django 5.1.3 on 2024-11-28 07:23 +from __future__ import annotations + +import uuid + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("tilavarauspalvelu", "0041_rename_recurring_reservation_uuid_to_ext_id"), + ] + + operations = [ + migrations.AddField( + model_name="reservation", + name="ext_id", + field=models.UUIDField(default=uuid.uuid4, null=True), + ), + ] diff --git a/tilavarauspalvelu/migrations/0043_populate_uuid_values.py b/tilavarauspalvelu/migrations/0043_populate_uuid_values.py new file mode 100644 index 0000000000..7ac0cdce23 --- /dev/null +++ b/tilavarauspalvelu/migrations/0043_populate_uuid_values.py @@ -0,0 +1,22 @@ +# Generated by Django 5.1.3 on 2024-11-28 07:30 +from __future__ import annotations + +import uuid + +from django.db import migrations + + +def gen_uuid(apps, schema_editor) -> None: + Reservation = apps.get_model("tilavarauspalvelu", "Reservation") + rows = list(Reservation.objects.all()) + for row in rows: + row.ext_id = uuid.uuid4() + Reservation.objects.bulk_update(rows, ["ext_id"]) + + +class Migration(migrations.Migration): + dependencies = [ + ("tilavarauspalvelu", "0042_add_reservation_uuids"), + ] + + operations = [migrations.RunPython(gen_uuid, migrations.RunPython.noop)] diff --git a/tilavarauspalvelu/migrations/0044_change_uuid_to_unique.py b/tilavarauspalvelu/migrations/0044_change_uuid_to_unique.py new file mode 100644 index 0000000000..0e3307963c --- /dev/null +++ b/tilavarauspalvelu/migrations/0044_change_uuid_to_unique.py @@ -0,0 +1,20 @@ +# Generated by Django 5.1.3 on 2024-11-28 07:31 +from __future__ import annotations + +import uuid + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("tilavarauspalvelu", "0043_populate_uuid_values"), + ] + + operations = [ + migrations.AlterField( + model_name="reservation", + name="ext_id", + field=models.UUIDField(default=uuid.uuid4, editable=False, unique=True), + ), + ] diff --git a/tilavarauspalvelu/migrations/0045_reservationstatistic_reservation_uuid.py b/tilavarauspalvelu/migrations/0045_reservationstatistic_reservation_uuid.py new file mode 100644 index 0000000000..a78d864d2d --- /dev/null +++ b/tilavarauspalvelu/migrations/0045_reservationstatistic_reservation_uuid.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.3 on 2024-11-28 07:48 +from __future__ import annotations + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("tilavarauspalvelu", "0044_change_uuid_to_unique"), + ] + + operations = [ + migrations.AddField( + model_name="reservationstatistic", + name="reservation_uuid", + field=models.CharField(blank=True, default="", max_length=255), + ), + ] diff --git a/tilavarauspalvelu/models/recurring_reservation/model.py b/tilavarauspalvelu/models/recurring_reservation/model.py index 25b0f26dd9..7747e0b63a 100644 --- a/tilavarauspalvelu/models/recurring_reservation/model.py +++ b/tilavarauspalvelu/models/recurring_reservation/model.py @@ -1,6 +1,6 @@ from __future__ import annotations -import uuid as uuid_ +import uuid from functools import cached_property from typing import TYPE_CHECKING @@ -27,9 +27,9 @@ class RecurringReservation(models.Model): + ext_id: uuid.UUID = models.UUIDField(default=uuid.uuid4, editable=False, unique=True) # ID for external systems name: str = models.CharField(max_length=255, blank=True, default="") description: str = models.CharField(max_length=500, blank=True, default="") - uuid: uuid_.UUID = models.UUIDField(default=uuid_.uuid4, editable=False, unique=True) created: datetime.datetime = models.DateTimeField(auto_now_add=True) begin_date: datetime.date | None = models.DateField(null=True) diff --git a/tilavarauspalvelu/models/reservation/model.py b/tilavarauspalvelu/models/reservation/model.py index 2d3699c6e4..cd2adf3818 100644 --- a/tilavarauspalvelu/models/reservation/model.py +++ b/tilavarauspalvelu/models/reservation/model.py @@ -1,6 +1,7 @@ from __future__ import annotations import datetime +import uuid from decimal import Decimal from functools import cached_property from typing import TYPE_CHECKING @@ -46,6 +47,7 @@ class Reservation(SerializableMixin, models.Model): # Basic information + ext_id: uuid.UUID = models.UUIDField(default=uuid.uuid4, editable=False, unique=True) # ID for external systems sku: str = models.CharField(max_length=255, blank=True, default="") name: str = models.CharField(max_length=255, blank=True, default="") description: str = models.CharField(max_length=255, blank=True, default="") diff --git a/tilavarauspalvelu/models/reservation_statistic/model.py b/tilavarauspalvelu/models/reservation_statistic/model.py index 0f3ace0eb7..2c4531ad12 100644 --- a/tilavarauspalvelu/models/reservation_statistic/model.py +++ b/tilavarauspalvelu/models/reservation_statistic/model.py @@ -136,6 +136,7 @@ class ReservationStatistic(models.Model): recurrence_begin_date: datetime.date | None = models.DateField(null=True) recurrence_end_date: datetime.date | None = models.DateField(null=True) recurrence_uuid: str = models.CharField(max_length=255, default="", blank=True) + reservation_uuid: str = models.CharField(max_length=255, default="", blank=True) reservee_uuid: str = models.CharField(max_length=255, default="", blank=True) reservee_used_ad_login: bool = models.BooleanField(default=False, blank=True) is_applied: bool = models.BooleanField(default=False, blank=True) @@ -204,7 +205,8 @@ def for_reservation(cls, reservation: Reservation, *, save: bool = True) -> Rese statistic.purpose_name = reservation.purpose.name if reservation.purpose else "" statistic.recurrence_begin_date = getattr(recurring_reservation, "begin_date", None) statistic.recurrence_end_date = getattr(recurring_reservation, "end_date", None) - statistic.recurrence_uuid = getattr(recurring_reservation, "uuid", "") + statistic.recurrence_uuid = str(getattr(recurring_reservation, "ext_id", "")) + statistic.reservation_uuid = str(reservation.ext_id) statistic.reservation = reservation statistic.reservation_confirmed_at = reservation.confirmed_at statistic.reservation_created_at = reservation.created_at