forked from uncloud/uncloud
Remove legacy ungleich_service migrations
This commit is contained in:
parent
c0e12884e1
commit
dd0c1cba94
5 changed files with 31 additions and 61 deletions
|
|
@ -46,7 +46,8 @@ class GenericServiceProduct(Product):
|
|||
decimal_places=AMOUNT_DECIMALS,
|
||||
validators=[MinValueValidator(0)])
|
||||
|
||||
def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH):
|
||||
@property
|
||||
def recurring_price(self):
|
||||
# FIXME: handle recurring_period somehow.
|
||||
return self.custom_recurring_price
|
||||
|
||||
|
|
|
|||
|
|
@ -23,12 +23,26 @@ class MatrixServiceProductSerializer(serializers.ModelSerializer):
|
|||
read_only_fields = ['uuid', 'order', 'owner', 'status']
|
||||
|
||||
class GenericServiceProductSerializer(serializers.ModelSerializer):
|
||||
# Custom field used at creation (= ordering) only.
|
||||
recurring_period = serializers.ChoiceField(
|
||||
choices=GenericServiceProduct.allowed_recurring_periods())
|
||||
|
||||
class Meta:
|
||||
model = GenericServiceProduct
|
||||
fields = ['uuid', 'order', 'owner', 'status', 'custom_recurring_price',
|
||||
'custom_description', 'custom_one_time_price', 'recurring_period']
|
||||
'custom_description', 'custom_one_time_price']
|
||||
read_only_fields = ['uuid', 'order', 'owner', 'status']
|
||||
|
||||
class OrderGenericServiceProductSerializer(GenericServiceProductSerializer):
|
||||
recurring_period = serializers.ChoiceField(
|
||||
choices=GenericServiceProduct.allowed_recurring_periods())
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -44,11 +44,13 @@ class MatrixServiceProductViewSet(ProductViewSet):
|
|||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
order_recurring_period = serializer.validated_data.pop("recurring_period")
|
||||
order_billing_address = serializer.validated_data.pop("billing_address")
|
||||
|
||||
# Create base order.)
|
||||
order = Order.objects.create(
|
||||
recurring_period=order_recurring_period,
|
||||
owner=request.user,
|
||||
billing_address=order_billing_address,
|
||||
starting_date=timezone.now()
|
||||
)
|
||||
order.save()
|
||||
|
|
@ -72,22 +74,29 @@ class MatrixServiceProductViewSet(ProductViewSet):
|
|||
|
||||
class GenericServiceProductViewSet(ProductViewSet):
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
serializer_class = GenericServiceProductSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
return GenericServiceProduct.objects.filter(owner=self.request.user)
|
||||
|
||||
def get_serializer_class(self):
|
||||
if self.action == 'create':
|
||||
return OrderGenericServiceProductSerializer
|
||||
else:
|
||||
return GenericServiceProductSerializer
|
||||
|
||||
@transaction.atomic
|
||||
def create(self, request):
|
||||
# Extract serializer data.
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
order_recurring_period = serializer.validated_data.pop("recurring_period")
|
||||
order_billing_address = serializer.validated_data.pop("billing_address")
|
||||
|
||||
# Create base order.
|
||||
order = Order.objects.create(
|
||||
recurring_period=order_recurring_period,
|
||||
owner=request.user,
|
||||
billing_address=order_billing_address,
|
||||
starting_date=timezone.now()
|
||||
)
|
||||
order.save()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue