mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-02-22 23:52:00 +00:00
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
from django.db import models
|
|
from django.utils import timezone
|
|
from api.models import User
|
|
|
|
# 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.CharField(primary_key=True, max_length=255)
|
|
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 BillFormula(models.Model):
|
|
id = models.CharField(primary_key=True, max_length=255)
|
|
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.CharField(primary_key=True, max_length=255)
|
|
amount = models.FloatField()
|
|
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='topups')
|
|
paid = models.BooleanField(default=False)
|
|
created_at = models.DateTimeField(default=timezone.now)
|
|
updated_at = models.DateTimeField(auto_now=True)
|
|
|
|
def __str__(self):
|
|
return f"Topup for {self.user}"
|