Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

individal admin tweaks for wallet #4386

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/hct_mis_api/apps/household/admin/individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 (
Expand Down
4 changes: 0 additions & 4 deletions src/hct_mis_api/apps/payment/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 3 additions & 17 deletions src/hct_mis_api/apps/payment/migrations/0141_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
25 changes: 25 additions & 0 deletions src/hct_mis_api/apps/payment/migrations/0147_migration.py
Original file line number Diff line number Diff line change
@@ -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',
),
]
13 changes: 0 additions & 13 deletions src/hct_mis_api/apps/payment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)

Expand Down
Loading