Skip to content

Commit

Permalink
fix_individual_household_update_grievance_ticket_nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
marekbiczysko committed Dec 27, 2024
1 parent c3adb14 commit a81ee69
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
25 changes: 25 additions & 0 deletions src/hct_mis_api/apps/grievance/migrations/0007_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 3.2.25 on 2024-12-27 12:53

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('household', '0006_migration'),
('grievance', '0006_migration'),
]

operations = [
migrations.AlterField(
model_name='tickethouseholddataupdatedetails',
name='household',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='household_data_update_ticket_details', to='household.household'),
),
migrations.AlterField(
model_name='ticketindividualdataupdatedetails',
name='individual',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='individual_data_update_ticket_details', to='household.individual'),
),
]
20 changes: 17 additions & 3 deletions src/hct_mis_api/apps/grievance/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.core.validators import MinValueValidator
from django.db import models
from django.db.models import JSONField, Q, QuerySet, UniqueConstraint
from django.db.models.signals import post_save
from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver
from django.utils.functional import cached_property
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -691,14 +691,21 @@ class TicketHouseholdDataUpdateDetails(TimeStampedUUIDModel):
"household.Household",
related_name="household_data_update_ticket_details",
on_delete=models.CASCADE,
null=True,
)
household_data = JSONField(null=True)

class Meta:
verbose_name_plural = "Ticket Household Data Update Details"


@receiver(post_delete, sender=TicketHouseholdDataUpdateDetails)
def delete_grievance_ticket_on_household_details_update_delete(
sender: TicketHouseholdDataUpdateDetails, instance: TicketHouseholdDataUpdateDetails, **kwargs: Any
) -> None:
if hasattr(instance, "ticket"):
instance.ticket.delete()


class TicketIndividualDataUpdateDetails(TimeStampedUUIDModel):
STATUS_FLOW = GENERAL_STATUS_FLOW

Expand All @@ -711,7 +718,6 @@ class TicketIndividualDataUpdateDetails(TimeStampedUUIDModel):
"household.Individual",
related_name="individual_data_update_ticket_details",
on_delete=models.CASCADE,
null=True,
)
individual_data = JSONField(null=True)
role_reassign_data = JSONField(default=dict)
Expand All @@ -724,6 +730,14 @@ class Meta:
verbose_name_plural = "Ticket Individual Data Update Details"


@receiver(post_delete, sender=TicketIndividualDataUpdateDetails)
def delete_grievance_ticket_on_individual_details_update_delete(
sender: TicketIndividualDataUpdateDetails, instance: TicketIndividualDataUpdateDetails, **kwargs: Any
) -> None:
if hasattr(instance, "ticket"):
instance.ticket.delete()


class TicketAddIndividualDetails(TimeStampedUUIDModel):
STATUS_FLOW = GENERAL_STATUS_FLOW

Expand Down

0 comments on commit a81ee69

Please sign in to comment.