2020-02-28 13:46:33 +00:00
|
|
|
from rest_framework import serializers
|
2020-04-17 08:08:33 +00:00
|
|
|
from .models import *
|
2020-03-03 09:51:16 +00:00
|
|
|
from uncloud_vm.serializers import ManagedVMProductSerializer
|
2020-02-29 08:08:30 +00:00
|
|
|
from uncloud_vm.models import VMProduct
|
2020-04-18 06:30:45 +00:00
|
|
|
from uncloud_pay.models import RecurringPeriod, BillingAddress
|
2020-02-28 13:46:33 +00:00
|
|
|
|
2020-04-18 08:40:11 +00:00
|
|
|
# XXX: the OrderSomethingSomthingProductSerializer classes add a lot of
|
|
|
|
# boilerplate: can we reduce it somehow?
|
|
|
|
|
2020-02-28 13:46:33 +00:00
|
|
|
class MatrixServiceProductSerializer(serializers.ModelSerializer):
|
2020-03-03 09:51:16 +00:00
|
|
|
vm = ManagedVMProductSerializer()
|
|
|
|
|
2020-04-18 08:40:11 +00:00
|
|
|
class Meta:
|
|
|
|
model = MatrixServiceProduct
|
2020-08-01 16:38:38 +00:00
|
|
|
fields = ['order', 'owner', 'status', 'vm', 'domain',
|
2020-04-18 08:40:11 +00:00
|
|
|
'recurring_period']
|
2020-08-01 16:38:38 +00:00
|
|
|
read_only_fields = ['order', 'owner', 'status']
|
2020-04-18 08:40:11 +00:00
|
|
|
|
|
|
|
class OrderMatrixServiceProductSerializer(MatrixServiceProductSerializer):
|
2020-10-06 13:46:22 +00:00
|
|
|
# recurring_period = serializers.ChoiceField(
|
|
|
|
# choices=MatrixServiceProduct.allowed_recurring_periods())
|
2020-02-28 15:26:45 +00:00
|
|
|
|
2020-04-18 06:30:45 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2020-04-18 08:40:11 +00:00
|
|
|
super(OrderMatrixServiceProductSerializer, self).__init__(*args, **kwargs)
|
2020-04-18 06:30:45 +00:00
|
|
|
self.fields['billing_address'] = serializers.ChoiceField(
|
2020-04-18 08:40:11 +00:00
|
|
|
choices=BillingAddress.get_addresses_for(
|
|
|
|
self.context['request'].user)
|
|
|
|
)
|
2020-04-18 06:30:45 +00:00
|
|
|
|
2020-02-28 13:46:33 +00:00
|
|
|
class Meta:
|
2020-04-18 08:40:11 +00:00
|
|
|
model = MatrixServiceProductSerializer.Meta.model
|
|
|
|
fields = MatrixServiceProductSerializer.Meta.fields + [
|
|
|
|
'recurring_period', 'billing_address'
|
|
|
|
]
|
|
|
|
read_only_fields = MatrixServiceProductSerializer.Meta.read_only_fields
|
2020-04-17 08:08:33 +00:00
|
|
|
|
|
|
|
class GenericServiceProductSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = GenericServiceProduct
|
2020-08-01 16:38:38 +00:00
|
|
|
fields = ['order', 'owner', 'status', 'custom_recurring_price',
|
2020-04-18 08:39:57 +00:00
|
|
|
'custom_description', 'custom_one_time_price']
|
2020-08-01 16:38:38 +00:00
|
|
|
read_only_fields = [ 'owner', 'status']
|
2020-04-18 08:39:57 +00:00
|
|
|
|
|
|
|
class OrderGenericServiceProductSerializer(GenericServiceProductSerializer):
|
2020-10-06 13:46:22 +00:00
|
|
|
# recurring_period = serializers.ChoiceField(
|
|
|
|
# choices=GenericServiceProduct.allowed_recurring_periods())
|
2020-04-18 08:39:57 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(OrderGenericServiceProductSerializer, self).__init__(*args, **kwargs)
|
|
|
|
self.fields['billing_address'] = serializers.ChoiceField(
|
|
|
|
choices=BillingAddress.get_addresses_for(
|
|
|
|
self.context['request'].user)
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = GenericServiceProductSerializer.Meta.model
|
|
|
|
fields = GenericServiceProductSerializer.Meta.fields + [
|
|
|
|
'recurring_period', 'billing_address'
|
|
|
|
]
|
|
|
|
read_only_fields = GenericServiceProductSerializer.Meta.read_only_fields
|