Initial commit from monorepo
This commit is contained in:
78
billing_app/models.py
Normal file
78
billing_app/models.py
Normal file
@@ -0,0 +1,78 @@
|
||||
import uuid
|
||||
from django.db import models
|
||||
|
||||
|
||||
class AccountType(models.TextChoices):
|
||||
"""Типы аккаунтов в системе биллинга."""
|
||||
USER = 'USER', 'User Account'
|
||||
SERVICE = 'SERVICE', 'Service Account'
|
||||
|
||||
|
||||
class Account(models.Model):
|
||||
"""
|
||||
Аккаунт в системе биллинга.
|
||||
Хранит метаданные об аккаунтах, созданных в TigerBeetle.
|
||||
UUID используется как ID аккаунта в TigerBeetle (uuid.int).
|
||||
"""
|
||||
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
name = models.CharField(max_length=255, help_text="Название аккаунта")
|
||||
account_type = models.CharField(
|
||||
max_length=50,
|
||||
choices=AccountType.choices,
|
||||
default=AccountType.USER,
|
||||
)
|
||||
description = models.TextField(blank=True, null=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
@property
|
||||
def tigerbeetle_id(self):
|
||||
"""ID аккаунта в TigerBeetle (128-bit int из UUID)."""
|
||||
return self.uuid.int
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name} ({self.account_type})"
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Account"
|
||||
verbose_name_plural = "Accounts"
|
||||
ordering = ['-created_at']
|
||||
|
||||
|
||||
class OperationCode(models.Model):
|
||||
"""
|
||||
Код операции (справочник типов транзакций).
|
||||
Используется как 'code' поле в TigerBeetle transfer.
|
||||
"""
|
||||
code = models.PositiveIntegerField(unique=True, help_text="Числовой код для TigerBeetle")
|
||||
name = models.CharField(max_length=255, unique=True, help_text="Название операции")
|
||||
description = models.TextField(blank=True, null=True)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.code}: {self.name}"
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Operation Code"
|
||||
verbose_name_plural = "Operation Codes"
|
||||
ordering = ['code']
|
||||
|
||||
|
||||
class ServiceAccount(models.Model):
|
||||
"""
|
||||
Сервисный аккаунт (банк, revenue, etc).
|
||||
Это Account с особым назначением в системе.
|
||||
"""
|
||||
account = models.OneToOneField(
|
||||
Account,
|
||||
on_delete=models.CASCADE,
|
||||
primary_key=True,
|
||||
related_name='service_info'
|
||||
)
|
||||
slug = models.SlugField(unique=True, help_text="Уникальный идентификатор (bank, revenue, etc)")
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.slug}: {self.account.name}"
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Service Account"
|
||||
verbose_name_plural = "Service Accounts"
|
||||
Reference in New Issue
Block a user