Make recurring period a database model

- For easier handling (foreignkeys, many2many)
- For higher flexibility (users can define their own periods)
This commit is contained in:
Nico Schottelius 2020-10-06 15:46:22 +02:00
commit 992c7c551e
11 changed files with 588 additions and 362 deletions

View file

@ -15,8 +15,8 @@ class MatrixServiceProduct(models.Model):
domain = models.CharField(max_length=255, default='domain.tld')
# Default recurring price is PER_MONT, see Product class.
def recurring_price(self, recurring_period=RecurringPeriod.PER_30D):
return self.monthly_managment_fee
# def recurring_price(self, recurring_period=RecurringPeriod.PER_30D):
# return self.monthly_managment_fee
@staticmethod
def base_image():
@ -24,11 +24,11 @@ class MatrixServiceProduct(models.Model):
#e return VMDiskImageProduct.objects.get(uuid="93e564c5-adb3-4741-941f-718f76075f02")
return False
@staticmethod
def allowed_recurring_periods():
return list(filter(
lambda pair: pair[0] in [RecurringPeriod.PER_30D],
RecurringPeriod.choices))
# @staticmethod
# def allowed_recurring_periods():
# return list(filter(
# lambda pair: pair[0] in [RecurringPeriod.PER_30D],
# RecurringPeriod.choices))
@property
def one_time_price(self):

View file

@ -17,8 +17,8 @@ class MatrixServiceProductSerializer(serializers.ModelSerializer):
read_only_fields = ['order', 'owner', 'status']
class OrderMatrixServiceProductSerializer(MatrixServiceProductSerializer):
recurring_period = serializers.ChoiceField(
choices=MatrixServiceProduct.allowed_recurring_periods())
# recurring_period = serializers.ChoiceField(
# choices=MatrixServiceProduct.allowed_recurring_periods())
def __init__(self, *args, **kwargs):
super(OrderMatrixServiceProductSerializer, self).__init__(*args, **kwargs)
@ -42,8 +42,8 @@ class GenericServiceProductSerializer(serializers.ModelSerializer):
read_only_fields = [ 'owner', 'status']
class OrderGenericServiceProductSerializer(GenericServiceProductSerializer):
recurring_period = serializers.ChoiceField(
choices=GenericServiceProduct.allowed_recurring_periods())
# recurring_period = serializers.ChoiceField(
# choices=GenericServiceProduct.allowed_recurring_periods())
def __init__(self, *args, **kwargs):
super(OrderGenericServiceProductSerializer, self).__init__(*args, **kwargs)