From ced6c18d00b95fe38b1e01d70544aebb5143fcbb Mon Sep 17 00:00:00 2001 From: Pawan Verma Date: Mon, 16 Dec 2024 18:32:29 +0530 Subject: [PATCH] Add unique_together on completed work model, migration --- .../0063_alter_completedwork_unique_together.py | 16 ++++++++++++++++ commcare_connect/opportunity/models.py | 3 +++ 2 files changed, 19 insertions(+) create mode 100644 commcare_connect/opportunity/migrations/0063_alter_completedwork_unique_together.py diff --git a/commcare_connect/opportunity/migrations/0063_alter_completedwork_unique_together.py b/commcare_connect/opportunity/migrations/0063_alter_completedwork_unique_together.py new file mode 100644 index 00000000..d0359b31 --- /dev/null +++ b/commcare_connect/opportunity/migrations/0063_alter_completedwork_unique_together.py @@ -0,0 +1,16 @@ +# Generated by Django 4.2.5 on 2024-12-16 13:02 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("opportunity", "0062_opportunityaccess_invited_date"), + ] + + operations = [ + migrations.AlterUniqueTogether( + name="completedwork", + unique_together={("entity_id", "payment_unit")}, + ), + ] diff --git a/commcare_connect/opportunity/models.py b/commcare_connect/opportunity/models.py index 6214d3fc..979f80fb 100644 --- a/commcare_connect/opportunity/models.py +++ b/commcare_connect/opportunity/models.py @@ -452,6 +452,9 @@ class CompletedWork(models.Model): status_modified_date = models.DateTimeField(null=True) payment_date = models.DateTimeField(null=True) + class Meta: + unique_together = ("entity_id", "payment_unit") + def __init__(self, *args, **kwargs): self.status = CompletedWorkStatus.incomplete self.status_modified_date = now()