From 80fc27fd74f11576b0d5f532ad4acf39cd159513 Mon Sep 17 00:00:00 2001 From: i701 Date: Sun, 27 Jul 2025 12:17:12 +0500 Subject: [PATCH] =?UTF-8?q?feat(topup):=20add=20payment=5Ftype=20field=20a?= =?UTF-8?q?nd=20update=20AdminTopupCreateView=20to=20handle=20payment=20ty?= =?UTF-8?q?pe=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- billing/migrations/0015_topup_payment_type.py | 21 +++++++++++++++++++ billing/models.py | 8 +++++++ billing/views.py | 14 +++++++------ 3 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 billing/migrations/0015_topup_payment_type.py diff --git a/billing/migrations/0015_topup_payment_type.py b/billing/migrations/0015_topup_payment_type.py new file mode 100644 index 0000000..7fff297 --- /dev/null +++ b/billing/migrations/0015_topup_payment_type.py @@ -0,0 +1,21 @@ +# Generated by Django 5.2 on 2025-07-27 07:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("billing", "0014_wallettransaction"), + ] + + operations = [ + migrations.AddField( + model_name="topup", + name="payment_type", + field=models.CharField( + choices=[("CASH", "Cash"), ("TRANSFER", "Transfer")], + default="TRANSFER", + max_length=20, + ), + ), + ] diff --git a/billing/models.py b/billing/models.py index 969e31d..8689f92 100644 --- a/billing/models.py +++ b/billing/models.py @@ -66,6 +66,14 @@ class Topup(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) amount = models.FloatField() user = models.ForeignKey(user, on_delete=models.CASCADE, related_name="topups") + payment_type = models.CharField( + max_length=20, + choices=[ + ("CASH", "Cash"), + ("TRANSFER", "Transfer"), + ], + default="TRANSFER", + ) paid = models.BooleanField(default=False) paid_at = models.DateTimeField(null=True, blank=True) status = models.CharField( diff --git a/billing/views.py b/billing/views.py index b2f5e65..f0c27b8 100644 --- a/billing/views.py +++ b/billing/views.py @@ -624,14 +624,16 @@ class AdminTopupCreateView(StaffEditorPermissionMixin, generics.CreateAPIView): {"message": "User not found."}, status=status.HTTP_404_NOT_FOUND, ) - topup = Topup.objects.create(amount=amount, user=user) - description = f"Topup of {amount} MVR (Cash)" - WalletTransaction.objects.create( - user=user, + topup = Topup.objects.create( amount=amount, - transaction_type="TOPUP", - description=description, + user=user, + paid=True, + paid_at=timezone.now(), + payment_type="CASH", + status="PAID", ) + description = f"Topup of {amount} MVR (Cash)" + user.add_wallet_funds(amount, description, topup.id) serializer = TopupSerializer(topup) return Response(serializer.data, status=status.HTTP_201_CREATED)