diff --git a/engine/apps/api/serializers/on_call_shifts.py b/engine/apps/api/serializers/on_call_shifts.py index 15fe1a78..794c466f 100644 --- a/engine/apps/api/serializers/on_call_shifts.py +++ b/engine/apps/api/serializers/on_call_shifts.py @@ -46,7 +46,6 @@ class OnCallShiftSerializer(EagerLoadingMixin, serializers.ModelSerializer): "until", "frequency", "interval", - "until", "by_day", "source", "rolling_users", @@ -74,7 +73,7 @@ class OnCallShiftSerializer(EagerLoadingMixin, serializers.ModelSerializer): result = super().to_representation(instance) return result - def validate_name(self, name): # todo + def validate_name(self, name): organization = self.context["request"].auth.organization if name is None: return name @@ -147,12 +146,15 @@ class OnCallShiftSerializer(EagerLoadingMixin, serializers.ModelSerializer): "interval", "by_day", "until", + "rotation_start", ] if event_type == CustomOnCallShift.TYPE_OVERRIDE: for field in fields_to_update_for_overrides: value = None if field == "priority_level": value = 0 + elif field == "rotation_start": + value = validated_data["start"] validated_data[field] = value self._validate_frequency( diff --git a/engine/apps/schedules/migrations/0006_customoncallshift_rotation_start.py b/engine/apps/schedules/migrations/0006_customoncallshift_rotation_start.py index 9facd79b..682df514 100644 --- a/engine/apps/schedules/migrations/0006_customoncallshift_rotation_start.py +++ b/engine/apps/schedules/migrations/0006_customoncallshift_rotation_start.py @@ -1,17 +1,12 @@ # Generated by Django 3.2.13 on 2022-07-12 08:03 from django.db import migrations, models +from django.db.models import F def fill_rotation_start_field(apps, schema_editor): CustomOnCallShift = apps.get_model("schedules", "CustomOnCallShift") - shifts = CustomOnCallShift.objects.all() - shifts_to_update = [] - for shift in shifts: - shift.rotation_start = shift.start - shifts_to_update.append(shift) - - CustomOnCallShift.objects.bulk_update(shifts_to_update, ["rotation_start"], batch_size=5000) + CustomOnCallShift.objects.update(rotation_start=F("start")) class Migration(migrations.Migration): diff --git a/engine/apps/schedules/models/custom_on_call_shift.py b/engine/apps/schedules/models/custom_on_call_shift.py index 15c35da8..64d72ae8 100644 --- a/engine/apps/schedules/models/custom_on_call_shift.py +++ b/engine/apps/schedules/models/custom_on_call_shift.py @@ -236,7 +236,8 @@ class CustomOnCallShift(models.Model): result += ( f", frequency: {self.get_frequency_display()}, interval: {self.interval}, " f"week start: {self.week_start}, by day: {self.by_day}, by month: {self.by_month}, " - f"by monthday: {self.by_monthday}, until: {self.until.isoformat() if self.until else None}" + f"by monthday: {self.by_monthday}, rotation start: {self.rotation_start.isoformat()}, " + f"until: {self.until.isoformat() if self.until else None}" ) return result