mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-06-28 15:53:57 +00:00
Initial commit
This commit is contained in:
0
billing/__init__.py
Normal file
0
billing/__init__.py
Normal file
3
billing/admin.py
Normal file
3
billing/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
6
billing/apps.py
Normal file
6
billing/apps.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class BillingConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "billing"
|
56
billing/migrations/0001_initial.py
Normal file
56
billing/migrations/0001_initial.py
Normal file
@ -0,0 +1,56 @@
|
||||
# Generated by Django 5.1.2 on 2025-01-20 04:50
|
||||
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="Device",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.CharField(max_length=255, primary_key=True, serialize=False),
|
||||
),
|
||||
("name", models.CharField(max_length=255)),
|
||||
("mac", models.CharField(max_length=255)),
|
||||
(
|
||||
"reason_for_blocking",
|
||||
models.CharField(blank=True, max_length=255, null=True),
|
||||
),
|
||||
("is_active", models.BooleanField(default=False)),
|
||||
("registered", models.BooleanField(default=False)),
|
||||
("blocked", models.BooleanField(default=False)),
|
||||
(
|
||||
"blocked_by",
|
||||
models.CharField(
|
||||
choices=[("ADMIN", "Admin"), ("PARENT", "Parent")],
|
||||
default="PARENT",
|
||||
max_length=255,
|
||||
),
|
||||
),
|
||||
("expiry_date", models.DateTimeField(blank=True, null=True)),
|
||||
("created_at", models.DateTimeField(default=django.utils.timezone.now)),
|
||||
("updated_at", models.DateTimeField(auto_now=True)),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
related_name="devices",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
@ -0,0 +1,93 @@
|
||||
# Generated by Django 5.1.2 on 2025-01-20 06:58
|
||||
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("billing", "0001_initial"),
|
||||
("devices", "0003_device_delete_billformula_remove_topup_user_and_more"),
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="BillFormula",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.CharField(max_length=255, primary_key=True, serialize=False),
|
||||
),
|
||||
("formula", models.CharField(max_length=255)),
|
||||
("base_amount", models.FloatField()),
|
||||
("discount_percentage", models.FloatField()),
|
||||
("created_at", models.DateTimeField(default=django.utils.timezone.now)),
|
||||
("updated_at", models.DateTimeField(auto_now=True)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="Payment",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.CharField(max_length=255, primary_key=True, serialize=False),
|
||||
),
|
||||
("number_of_months", models.IntegerField()),
|
||||
("amount", models.FloatField()),
|
||||
("paid", models.BooleanField(default=False)),
|
||||
("paid_at", models.DateTimeField(blank=True, null=True)),
|
||||
(
|
||||
"method",
|
||||
models.CharField(
|
||||
choices=[("WALLET", "Wallet"), ("TRANSFER", "Transfer")],
|
||||
default="TRANSFER",
|
||||
max_length=255,
|
||||
),
|
||||
),
|
||||
("expires_at", models.DateTimeField(blank=True, null=True)),
|
||||
("created_at", models.DateTimeField(default=django.utils.timezone.now)),
|
||||
("updated_at", models.DateTimeField(auto_now=True)),
|
||||
(
|
||||
"devices",
|
||||
models.ManyToManyField(
|
||||
related_name="payments", to="devices.device"
|
||||
),
|
||||
),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="payments",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="Topup",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.CharField(max_length=255, primary_key=True, serialize=False),
|
||||
),
|
||||
("amount", models.FloatField()),
|
||||
("paid", models.BooleanField(default=False)),
|
||||
("created_at", models.DateTimeField(default=django.utils.timezone.now)),
|
||||
("updated_at", models.DateTimeField(auto_now=True)),
|
||||
(
|
||||
"user",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="topups",
|
||||
to=settings.AUTH_USER_MODEL,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name="Device",
|
||||
),
|
||||
]
|
0
billing/migrations/__init__.py
Normal file
0
billing/migrations/__init__.py
Normal file
51
billing/models.py
Normal file
51
billing/models.py
Normal file
@ -0,0 +1,51 @@
|
||||
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}"
|
3
billing/tests.py
Normal file
3
billing/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
2
billing/views.py
Normal file
2
billing/views.py
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
# Create your views here.
|
Reference in New Issue
Block a user