diff --git a/src/hct_mis_api/apps/household/admin/individual.py b/src/hct_mis_api/apps/household/admin/individual.py index 00d8d981a0..cd373a0f3c 100644 --- a/src/hct_mis_api/apps/household/admin/individual.py +++ b/src/hct_mis_api/apps/household/admin/individual.py @@ -36,6 +36,7 @@ IndividualRoleInHousehold, XlsxUpdateFile, ) +from hct_mis_api.apps.payment.models import DeliveryMechanismData from hct_mis_api.apps.utils.admin import ( BusinessAreaForIndividualCollectionListFilter, HOPEModelAdminBase, @@ -50,6 +51,18 @@ logger = logging.getLogger(__name__) +class IndividualDeliveryMechanismDataInline(admin.TabularInline): + model = DeliveryMechanismData + extra = 0 + fields = ("delivery_mechanism", "data", "is_valid") + readonly_fields = ("delivery_mechanism", "data", "is_valid") + show_change_link = True + can_delete = False + + def has_add_permission(self, request: HttpRequest, obj: Optional[Individual] = None) -> bool: + return False + + @admin.register(Individual) class IndividualAdmin( SoftDeletableAdminMixin, @@ -151,6 +164,7 @@ class IndividualAdmin( ("Others", {"classes": ("collapse",), "fields": ("__others__",)}), ] actions = ["count_queryset", "revalidate_phone_number_sync", "revalidate_phone_number_async"] + inlines = [IndividualDeliveryMechanismDataInline] def get_queryset(self, request: HttpRequest) -> QuerySet: return ( diff --git a/src/hct_mis_api/apps/payment/admin.py b/src/hct_mis_api/apps/payment/admin.py index 3f31bf1cab..0e4f060dc4 100644 --- a/src/hct_mis_api/apps/payment/admin.py +++ b/src/hct_mis_api/apps/payment/admin.py @@ -311,7 +311,6 @@ def has_delete_permission(self, request: HttpRequest, obj: Optional[Any] = None) class DeliveryMechanismPerPaymentPlanAdmin(HOPEModelAdminBase): list_display = ("delivery_mechanism_order", "delivery_mechanism", "payment_plan", "status") raw_id_fields = ("payment_plan", "financial_service_provider", "created_by", "sent_by") - exclude = ("delivery_mechanism_choice",) @admin.register(FinancialServiceProviderXlsxTemplate) @@ -392,7 +391,6 @@ class FspXlsxTemplatePerDeliveryMechanismAdmin(HOPEModelAdminBase): list_display = ("financial_service_provider", "delivery_mechanism", "xlsx_template", "created_by") fields = ("financial_service_provider", "delivery_mechanism", "xlsx_template") autocomplete_fields = ("financial_service_provider", "xlsx_template") - exclude = ("delivery_mechanism_choice",) form = FspXlsxTemplatePerDeliveryMechanismForm def save_model( @@ -450,7 +448,6 @@ class FspXlsxTemplatePerDeliveryMechanismAdminInline(admin.TabularInline): extra = 0 readonly_fields = ("created_by",) raw_id_fields = ("financial_service_provider",) - exclude = ("delivery_mechanism_choice",) @admin.register(FinancialServiceProvider) @@ -512,7 +509,6 @@ class DeliveryMechanismDataAdmin(HOPEModelAdminBase): list_display = ("individual", "delivery_mechanism", "is_valid") raw_id_fields = ("individual", "possible_duplicate_of") readonly_fields = ("possible_duplicate_of", "unique_key", "signature_hash", "validation_errors") - exclude = ("delivery_mechanism_choice",) @admin.register(DeliveryMechanism) diff --git a/src/hct_mis_api/apps/payment/migrations/0141_migration.py b/src/hct_mis_api/apps/payment/migrations/0141_migration.py index de5e8c69ec..672f57b0dc 100644 --- a/src/hct_mis_api/apps/payment/migrations/0141_migration.py +++ b/src/hct_mis_api/apps/payment/migrations/0141_migration.py @@ -17,29 +17,15 @@ def data_migration_financialserviceprovider_delivery_mechanisms(apps, schema_edi def data_migration_deliverymechanismdata_delivery_mechanism(apps, schema_editor): - DeliveryMechanismData = apps.get_model("payment", "DeliveryMechanismData") - DeliveryMechanism = apps.get_model("payment", "DeliveryMechanism") - - for dm in DeliveryMechanism.objects.all(): - DeliveryMechanismData.objects.filter(delivery_mechanism_choice=dm.name).update(delivery_mechanism=dm) + pass def data_migration_deliverymechanismperpaymentplan_delivery_mechanism(apps, schema_editor): - DeliveryMechanismPerPaymentPlan = apps.get_model("payment", "DeliveryMechanismPerPaymentPlan") - DeliveryMechanism = apps.get_model("payment", "DeliveryMechanism") - - for dm in DeliveryMechanism.objects.all(): - DeliveryMechanismPerPaymentPlan.objects.filter(delivery_mechanism_choice=dm.name).update(delivery_mechanism=dm) + pass def data_migration_fspxlsxtemplateperdeliverymechanism_delivery_mechanism(apps, schema_editor): - FspXlsxTemplatePerDeliveryMechanism = apps.get_model("payment", "FspXlsxTemplatePerDeliveryMechanism") - DeliveryMechanism = apps.get_model("payment", "DeliveryMechanism") - - for dm in DeliveryMechanism.objects.all(): - FspXlsxTemplatePerDeliveryMechanism.objects.filter(delivery_mechanism_choice=dm.name).update( - delivery_mechanism=dm - ) + pass def data_migration_payment_delivery_type(apps, schema_editor): diff --git a/src/hct_mis_api/apps/payment/migrations/0147_migration.py b/src/hct_mis_api/apps/payment/migrations/0147_migration.py new file mode 100644 index 0000000000..a67f542dea --- /dev/null +++ b/src/hct_mis_api/apps/payment/migrations/0147_migration.py @@ -0,0 +1,25 @@ +# Generated by Django 3.2.25 on 2024-10-30 17:40 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('payment', '0146_migration'), + ] + + operations = [ + migrations.RemoveField( + model_name='deliverymechanismdata', + name='delivery_mechanism_choice', + ), + migrations.RemoveField( + model_name='deliverymechanismperpaymentplan', + name='delivery_mechanism_choice', + ), + migrations.RemoveField( + model_name='fspxlsxtemplateperdeliverymechanism', + name='delivery_mechanism_choice', + ), + ] diff --git a/src/hct_mis_api/apps/payment/models.py b/src/hct_mis_api/apps/payment/models.py index 3f945c4745..11033fe011 100644 --- a/src/hct_mis_api/apps/payment/models.py +++ b/src/hct_mis_api/apps/payment/models.py @@ -1388,9 +1388,6 @@ class FspXlsxTemplatePerDeliveryMechanism(TimeStampedUUIDModel): financial_service_provider = models.ForeignKey( "FinancialServiceProvider", on_delete=models.CASCADE, related_name="fsp_xlsx_template_per_delivery_mechanisms" ) - delivery_mechanism_choice = models.CharField( - max_length=255, verbose_name=_("Delivery Mechanism"), choices=DeliveryMechanismChoices.DELIVERY_TYPE_CHOICES - ) # TODO MB drop later delivery_mechanism = models.ForeignKey("DeliveryMechanism", on_delete=models.SET_NULL, null=True) xlsx_template = models.ForeignKey( "FinancialServiceProviderXlsxTemplate", @@ -1533,9 +1530,6 @@ class Status(models.TextChoices): null=True, ) status = FSMField(default=Status.NOT_SENT, protected=False, db_index=True) - delivery_mechanism_choice = models.CharField( - max_length=255, choices=DeliveryMechanismChoices.DELIVERY_TYPE_CHOICES, db_index=True, null=True - ) # TODO MB drop later delivery_mechanism = models.ForeignKey("DeliveryMechanism", on_delete=models.SET_NULL, null=True) delivery_mechanism_order = models.PositiveIntegerField() @@ -2287,13 +2281,6 @@ class DeliveryMechanismData(MergeStatusModel, TimeStampedUUIDModel, SignatureMix individual = models.ForeignKey( "household.Individual", on_delete=models.CASCADE, related_name="delivery_mechanisms_data" ) - delivery_mechanism_choice = models.CharField( - max_length=255, - verbose_name=_("Delivery Mechanism"), - choices=DeliveryMechanismChoices.DELIVERY_TYPE_CHOICES, - null=True, - blank=True, - ) # TODO MB drop later delivery_mechanism = models.ForeignKey("DeliveryMechanism", on_delete=models.PROTECT) data = JSONField(default=dict, blank=True)