mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-07-07 18:26:30 +00:00
81 lines
2.6 KiB
Python
81 lines
2.6 KiB
Python
from django.db import models
|
|
from django.utils import timezone
|
|
from api.models import User
|
|
import uuid
|
|
|
|
# Create your models here.
|
|
|
|
from devices.models import Device
|
|
|
|
# Create your models here.
|
|
|
|
|
|
class Payment(models.Model):
|
|
PAYMENT_TYPES = [
|
|
("WALLET", "Wallet"),
|
|
("TRANSFER", "Transfer"),
|
|
]
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
mib_reference = models.CharField(default="", null=True, blank=True)
|
|
number_of_months = models.IntegerField()
|
|
amount = models.FloatField()
|
|
paid = models.BooleanField(default=False)
|
|
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="payments")
|
|
paid_at = models.DateTimeField(null=True, blank=True)
|
|
method = models.CharField(max_length=255, choices=PAYMENT_TYPES, default="TRANSFER")
|
|
expires_at = models.DateTimeField(null=True, blank=True)
|
|
created_at = models.DateTimeField(default=timezone.now)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
devices = models.ManyToManyField(Device, related_name="payments")
|
|
|
|
def __str__(self):
|
|
return f"Payment by {self.user}"
|
|
|
|
class Meta:
|
|
ordering = ["-created_at"]
|
|
|
|
|
|
class BillFormula(models.Model):
|
|
formula = models.CharField(max_length=255)
|
|
base_amount = models.FloatField()
|
|
discount_percentage = models.FloatField()
|
|
created_at = models.DateTimeField(default=timezone.now)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
def __str__(self):
|
|
return self.formula
|
|
|
|
|
|
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")
|
|
paid = models.BooleanField(default=False)
|
|
paid_at = models.DateTimeField(null=True, blank=True)
|
|
status = models.CharField(
|
|
max_length=20,
|
|
choices=[
|
|
("PENDING", "Pending"),
|
|
("PAID", "Paid"),
|
|
("CANCELLED", "Cancelled"),
|
|
],
|
|
default="PENDING",
|
|
)
|
|
mib_reference = models.CharField(default="", null=True, blank=True)
|
|
expires_at = models.DateTimeField(null=True, blank=True)
|
|
expiry_notification_sent = models.BooleanField(default=False)
|
|
created_at = models.DateTimeField(default=timezone.now)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
@property
|
|
def is_expired(self):
|
|
if self.expires_at is None:
|
|
return False
|
|
return timezone.now() > self.expires_at
|
|
|
|
def __str__(self):
|
|
return f"Topup for {self.user}"
|
|
|
|
class Meta:
|
|
ordering = ["-created_at"]
|