From c38404da8b3baad2b564a4abbe83bc4975c32fb5 Mon Sep 17 00:00:00 2001 From: Quang Son Le Date: Mon, 23 Dec 2024 17:50:57 +0100 Subject: [PATCH] POLIO-1252: remove deprecated field --- plugins/polio/api/rounds/round.py | 4 ++-- plugins/polio/api/shared_serializers.py | 8 +------- .../0214_remove_rounddatehistoryentry_reason.py | 16 ++++++++++++++++ plugins/polio/models/base.py | 2 -- 4 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 plugins/polio/migrations/0214_remove_rounddatehistoryentry_reason.py diff --git a/plugins/polio/api/rounds/round.py b/plugins/polio/api/rounds/round.py index cbbe59a5c7..0c56c33648 100644 --- a/plugins/polio/api/rounds/round.py +++ b/plugins/polio/api/rounds/round.py @@ -53,7 +53,7 @@ def create(self, validated_data): if started_at is not None or ended_at is not None: reason_for_delay = ReasonForDelay.objects.filter(key_name="INITIAL_DATA").first() datelog = RoundDateHistoryEntry.objects.create( - round=round, reason="INITIAL_DATA", reason_for_delay=reason_for_delay, modified_by=user + round=round, reason_for_delay=reason_for_delay, modified_by=user ) if started_at is not None: datelog.started_at = started_at @@ -95,7 +95,7 @@ def update(self, instance, validated_data): # Fallback on first reason available for account reason_for_delay = ReasonForDelay.filter(account=account).first() datelog = RoundDateHistoryEntry.objects.create( - round=instance, reason="INITIAL_DATA", reason_for_delay=reason_for_delay, modified_by=user + round=instance, reason_for_delay=reason_for_delay, modified_by=user ) if datelog is not None: # Replace instance with key_name to avoid validation error diff --git a/plugins/polio/api/shared_serializers.py b/plugins/polio/api/shared_serializers.py index f846557072..d7b22282bc 100644 --- a/plugins/polio/api/shared_serializers.py +++ b/plugins/polio/api/shared_serializers.py @@ -55,7 +55,6 @@ class Meta: model = RoundDateHistoryEntry fields = [ "created_at", - "reason", "reason_for_delay", "ended_at", "started_at", @@ -88,7 +87,6 @@ class Meta: model = RoundDateHistoryEntry fields = [ "created_at", - "reason", "reason_for_delay", "ended_at", "started_at", @@ -101,12 +99,8 @@ class Meta: modified_by = UserSerializer(required=False, read_only=True) round: Field = serializers.PrimaryKeyRelatedField(read_only=True, many=False) reason_for_delay = ReasonForDelayFieldSerializer() - reason = serializers.SerializerMethodField() - - @staticmethod - def get_reason(obj: RoundDateHistoryEntry): - return obj.reason_for_delay.key_name if obj.reason_for_delay else None + def validate(self, data): if data.get("reason_for_delay", None) is None: raise serializers.ValidationError("No reason provided") diff --git a/plugins/polio/migrations/0214_remove_rounddatehistoryentry_reason.py b/plugins/polio/migrations/0214_remove_rounddatehistoryentry_reason.py new file mode 100644 index 0000000000..5a381a88ae --- /dev/null +++ b/plugins/polio/migrations/0214_remove_rounddatehistoryentry_reason.py @@ -0,0 +1,16 @@ +# Generated by Django 4.2.17 on 2024-12-23 16:18 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("polio", "0213_alter_vaccinerequestform_vaccine_type"), + ] + + operations = [ + migrations.RemoveField( + model_name="rounddatehistoryentry", + name="reason", + ), + ] diff --git a/plugins/polio/models/base.py b/plugins/polio/models/base.py index 1a8738fa6f..6ab4d5c94c 100644 --- a/plugins/polio/models/base.py +++ b/plugins/polio/models/base.py @@ -181,8 +181,6 @@ class RoundDateHistoryEntry(models.Model): previous_ended_at = models.DateField(null=True, blank=True) started_at = models.DateField(null=True, blank=True) ended_at = models.DateField(null=True, blank=True) - # Deprecated. Cannot be deleted until the PowerBI dashboards are updated to use reason_for_delay instead - reason = models.CharField(null=True, blank=True, choices=DelayReasons.choices, max_length=200) reason_for_delay = models.ForeignKey( "ReasonForDelay", on_delete=models.PROTECT, null=True, blank=True, related_name="round_history_entries" )