2020-02-28 13:46:33 +00:00
|
|
|
from django.db import models
|
2020-04-17 08:08:33 +00:00
|
|
|
from uncloud_pay.models import Product, RecurringPeriod, AMOUNT_MAX_DIGITS, AMOUNT_DECIMALS
|
2020-03-09 15:37:56 +00:00
|
|
|
from uncloud_vm.models import VMProduct, VMDiskImageProduct
|
2020-04-17 08:08:33 +00:00
|
|
|
from django.core.validators import MinValueValidator
|
2020-02-28 13:46:33 +00:00
|
|
|
|
2020-09-28 18:59:08 +00:00
|
|
|
class MatrixServiceProduct(models.Model):
|
2020-02-28 13:46:33 +00:00
|
|
|
monthly_managment_fee = 20
|
|
|
|
|
|
|
|
description = "Managed Matrix HomeServer"
|
2020-02-28 15:26:45 +00:00
|
|
|
|
|
|
|
# Specific to Matrix-as-a-Service
|
2020-02-28 13:46:33 +00:00
|
|
|
vm = models.ForeignKey(
|
|
|
|
VMProduct, on_delete=models.CASCADE
|
|
|
|
)
|
2020-02-28 15:26:45 +00:00
|
|
|
domain = models.CharField(max_length=255, default='domain.tld')
|
2020-02-28 13:46:33 +00:00
|
|
|
|
2020-04-13 10:00:59 +00:00
|
|
|
# Default recurring price is PER_MONT, see Product class.
|
2020-10-06 13:46:22 +00:00
|
|
|
# def recurring_price(self, recurring_period=RecurringPeriod.PER_30D):
|
|
|
|
# return self.monthly_managment_fee
|
2020-02-28 15:26:45 +00:00
|
|
|
|
2020-03-09 15:37:56 +00:00
|
|
|
@staticmethod
|
|
|
|
def base_image():
|
|
|
|
# TODO: find a way to safely reference debian 10 image.
|
2020-08-01 16:38:38 +00:00
|
|
|
#e return VMDiskImageProduct.objects.get(uuid="93e564c5-adb3-4741-941f-718f76075f02")
|
|
|
|
return False
|
2020-03-09 15:37:56 +00:00
|
|
|
|
2020-10-06 13:46:22 +00:00
|
|
|
# @staticmethod
|
|
|
|
# def allowed_recurring_periods():
|
|
|
|
# return list(filter(
|
|
|
|
# lambda pair: pair[0] in [RecurringPeriod.PER_30D],
|
|
|
|
# RecurringPeriod.choices))
|
2020-03-03 09:51:16 +00:00
|
|
|
|
|
|
|
@property
|
2020-03-03 10:27:35 +00:00
|
|
|
def one_time_price(self):
|
2020-03-03 09:51:16 +00:00
|
|
|
return 30
|
2020-04-17 08:08:33 +00:00
|
|
|
|
2020-09-28 18:59:08 +00:00
|
|
|
class GenericServiceProduct(models.Model):
|
2020-04-17 08:08:33 +00:00
|
|
|
custom_description = models.TextField()
|
|
|
|
custom_recurring_price = models.DecimalField(default=0.0,
|
|
|
|
max_digits=AMOUNT_MAX_DIGITS,
|
|
|
|
decimal_places=AMOUNT_DECIMALS,
|
|
|
|
validators=[MinValueValidator(0)])
|
|
|
|
custom_one_time_price = models.DecimalField(default=0.0,
|
|
|
|
max_digits=AMOUNT_MAX_DIGITS,
|
|
|
|
decimal_places=AMOUNT_DECIMALS,
|
|
|
|
validators=[MinValueValidator(0)])
|
|
|
|
|
2020-04-18 08:39:57 +00:00
|
|
|
@property
|
|
|
|
def recurring_price(self):
|
2020-04-18 07:02:33 +00:00
|
|
|
# FIXME: handle recurring_period somehow.
|
2020-04-17 08:08:33 +00:00
|
|
|
return self.custom_recurring_price
|
|
|
|
|
|
|
|
@property
|
|
|
|
def description(self):
|
|
|
|
return self.custom_description
|
|
|
|
|
|
|
|
@property
|
|
|
|
def one_time_price(self):
|
|
|
|
return self.custom_one_time_price
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def allowed_recurring_periods():
|
|
|
|
return RecurringPeriod.choices
|