From b1649a6228a052edfaf2b429b55b8489f8b4aef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Thu, 27 Feb 2020 20:37:19 +0100 Subject: [PATCH] Remove product resolution from /order endpoint --- uncloud/uncloud_pay/models.py | 7 ------- uncloud/uncloud_pay/serializers.py | 31 +----------------------------- uncloud/uncloud_pay/views.py | 2 +- 3 files changed, 2 insertions(+), 38 deletions(-) diff --git a/uncloud/uncloud_pay/models.py b/uncloud/uncloud_pay/models.py index c4506a2..d7c4ff1 100644 --- a/uncloud/uncloud_pay/models.py +++ b/uncloud/uncloud_pay/models.py @@ -60,13 +60,6 @@ class Order(models.Model): choices = RecurringPeriod.choices, default = RecurringPeriod.PER_MONTH) - @property - def products(self): - # Blows up due to circular dependency... - # vms = VMProduct.objects.filter(order=self) - vms = [] - return vms - # def amount(self): # amount = recurring_price # if recurring and first_month: diff --git a/uncloud/uncloud_pay/serializers.py b/uncloud/uncloud_pay/serializers.py index d08f9cf..9449ee6 100644 --- a/uncloud/uncloud_pay/serializers.py +++ b/uncloud/uncloud_pay/serializers.py @@ -23,42 +23,13 @@ class PaymentMethodSerializer(serializers.ModelSerializer): fields = ['owner', 'primary', 'source', 'description'] class ProductSerializer(serializers.Serializer): - vms = VMProductSerializer(many=True, required=False) - - def create(self, validated_data): - owner = validated_data.pop('owner') - order = validated_data.pop('order') - - vms = validated_data.pop('vms') - for vm in vms: - VMProduct.objects.create(owner=owner, order=order, **vm) - - return True # FIXME: shoudl return created objects - + vms = VMProductSerializer(many=True, read_only=True) class OrderSerializer(serializers.ModelSerializer): - products = ProductSerializer() class Meta: model = Order fields = '__all__' - def create(self, validated_data): - products_data = validated_data.pop('products') - validated_data['owner'] = self.context["request"].user - - # FIXME: find something to do with this: - validated_data['recurring_price'] = 0 - validated_data['one_time_price'] = 0 - - order = Order.objects.create(**validated_data) - - # Forward product creation to ProductSerializer. - products = ProductSerializer(data=products_data) - products.is_valid(raise_exception=True) - products.save(order=order,owner=order.owner) - - return order - class UserSerializer(serializers.ModelSerializer): class Meta: model = get_user_model() diff --git a/uncloud/uncloud_pay/views.py b/uncloud/uncloud_pay/views.py index c641991..ea3cca7 100644 --- a/uncloud/uncloud_pay/views.py +++ b/uncloud/uncloud_pay/views.py @@ -42,7 +42,7 @@ class PaymentViewSet(viewsets.ReadOnlyModelViewSet): def get_queryset(self): return Payment.objects.filter(owner=self.request.user) -class OrderViewSet(viewsets.ModelViewSet): +class OrderViewSet(viewsets.ReadOnlyModelViewSet): serializer_class = OrderSerializer permission_classes = [permissions.IsAuthenticated]