2020-02-21 10:32:41 +00:00
|
|
|
from django.contrib.auth.models import AbstractUser
|
2020-03-18 13:53:26 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.core.validators import MinValueValidator
|
2020-02-21 10:32:41 +00:00
|
|
|
|
2020-05-08 08:56:03 +00:00
|
|
|
from uncloud_pay import AMOUNT_DECIMALS, AMOUNT_MAX_DIGITS
|
2020-03-18 13:53:26 +00:00
|
|
|
from uncloud_pay.models import get_balance_for_user
|
2020-02-21 15:33:37 +00:00
|
|
|
|
2020-02-21 10:32:41 +00:00
|
|
|
class User(AbstractUser):
|
2020-03-18 13:53:26 +00:00
|
|
|
"""
|
2020-03-18 14:19:06 +00:00
|
|
|
We use the standard user and add a maximum credit that is allowed
|
|
|
|
to be accumulated. After that we need to have warnings, cancellation, etc.
|
2020-03-18 13:53:26 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
maximum_credit = models.DecimalField(
|
|
|
|
default=0.0,
|
|
|
|
max_digits=AMOUNT_MAX_DIGITS,
|
|
|
|
decimal_places=AMOUNT_DECIMALS,
|
|
|
|
validators=[MinValueValidator(0)])
|
|
|
|
|
2020-05-10 19:47:44 +00:00
|
|
|
# Need to use the string here to prevent a circular import
|
|
|
|
primary_billing_address = models.ForeignKey('uncloud_pay.BillingAddress',
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
blank=True,
|
|
|
|
null=True)
|
|
|
|
|
2020-03-18 13:53:26 +00:00
|
|
|
@property
|
|
|
|
def balance(self):
|
|
|
|
return get_balance_for_user(self)
|