feat(wallet): implement wallet transaction model, views, and serializers for fund management
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m42s

This commit is contained in:
2025-07-25 14:38:34 +05:00
parent f8c91e8f14
commit 1554829b9a
11 changed files with 256 additions and 52 deletions

View File

@@ -8,6 +8,7 @@ from django.db import models
from .managers import CustomUserManager
from django.utils import timezone
import pyotp
from billing.models import WalletTransaction
class User(AbstractUser):
@@ -47,6 +48,31 @@ class User(AbstractUser):
def get_all_fields(self, instance):
return [field.name for field in instance.get_fields()]
def add_wallet_funds(self, amount, description="", reference_id=None):
self.wallet_balance += amount
self.save(update_fields=["wallet_balance"])
WalletTransaction.objects.create(
user=self,
amount=amount,
transaction_type="TOPUP",
description=description,
reference_id=reference_id,
)
def deduct_wallet_funds(self, amount, description="", reference_id=None):
if self.wallet_balance >= amount:
self.wallet_balance -= amount
self.save(update_fields=["wallet_balance"])
WalletTransaction.objects.create(
user=self,
amount=amount,
transaction_type="DEBIT",
description=description,
reference_id=reference_id,
)
return True
return False
objects = CustomUserManager()
@@ -110,7 +136,7 @@ class TemporaryUser(models.Model):
verbose_name_plural = "Temporary Users"
def __str__(self) -> str:
return str(self.t_username)
return f"{self.t_username}"
class Atoll(models.Model):