60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
import uuid
|
|
|
|
from django.contrib.auth.models import AbstractUser
|
|
from django.db import models
|
|
|
|
# from core.lib.customers import get_or_create, update_customer_fields
|
|
from core.util import logs
|
|
|
|
log = logs.get_logger(__name__)
|
|
|
|
SERVICE_CHOICES = (("nordigen", "Nordigen"),)
|
|
|
|
|
|
class User(AbstractUser):
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
payment_provider_id = models.CharField(max_length=255, null=True, blank=True)
|
|
billing_provider_id = models.CharField(max_length=255, null=True, blank=True)
|
|
email = models.EmailField(unique=True)
|
|
|
|
def get_notification_settings(self):
|
|
return NotificationSettings.objects.get_or_create(user=self)[0]
|
|
|
|
|
|
class NotificationSettings(models.Model):
|
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
|
ntfy_topic = models.CharField(max_length=255, null=True, blank=True)
|
|
ntfy_url = models.CharField(max_length=255, null=True, blank=True)
|
|
|
|
def __str__(self):
|
|
return f"Notification settings for {self.user}"
|
|
|
|
|
|
class Aggregator(models.Model):
|
|
"""
|
|
A connection to an API aggregator to pull transactions from bank accounts.
|
|
"""
|
|
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
|
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
|
name = models.CharField(max_length=255)
|
|
service = models.CharField(max_length=255, choices=SERVICE_CHOICES)
|
|
secret_id = models.CharField(max_length=1024, null=True, blank=True)
|
|
secret_key = models.CharField(max_length=1024, null=True, blank=True)
|
|
access_token = models.CharField(max_length=1024, null=True, blank=True)
|
|
access_token_expires = models.DateTimeField(null=True, blank=True)
|
|
poll_interval = models.IntegerField(default=10)
|
|
|
|
enabled = models.BooleanField(default=True)
|
|
|
|
def __str__(self):
|
|
return f"Aggregator ({self.service}) for {self.user}"
|
|
|
|
@classmethod
|
|
def get_by_id(cls, obj_id, user):
|
|
return cls.objects.get(id=obj_id, user=user)
|
|
|
|
@property
|
|
def client(self):
|
|
pass
|