mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-10-07 08:31:37 +00:00
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
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 4m42s
This commit is contained in:
@@ -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):
|
||||
|
Reference in New Issue
Block a user