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()