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]