Remove product resolution from /order endpoint
This commit is contained in:
parent
0e28e50bac
commit
b1649a6228
3 changed files with 2 additions and 38 deletions
|
@ -60,13 +60,6 @@ class Order(models.Model):
|
||||||
choices = RecurringPeriod.choices,
|
choices = RecurringPeriod.choices,
|
||||||
default = RecurringPeriod.PER_MONTH)
|
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):
|
# def amount(self):
|
||||||
# amount = recurring_price
|
# amount = recurring_price
|
||||||
# if recurring and first_month:
|
# if recurring and first_month:
|
||||||
|
|
|
@ -23,42 +23,13 @@ class PaymentMethodSerializer(serializers.ModelSerializer):
|
||||||
fields = ['owner', 'primary', 'source', 'description']
|
fields = ['owner', 'primary', 'source', 'description']
|
||||||
|
|
||||||
class ProductSerializer(serializers.Serializer):
|
class ProductSerializer(serializers.Serializer):
|
||||||
vms = VMProductSerializer(many=True, required=False)
|
vms = VMProductSerializer(many=True, read_only=True)
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
class OrderSerializer(serializers.ModelSerializer):
|
class OrderSerializer(serializers.ModelSerializer):
|
||||||
products = ProductSerializer()
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Order
|
model = Order
|
||||||
fields = '__all__'
|
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 UserSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = get_user_model()
|
model = get_user_model()
|
||||||
|
|
|
@ -42,7 +42,7 @@ class PaymentViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return Payment.objects.filter(owner=self.request.user)
|
return Payment.objects.filter(owner=self.request.user)
|
||||||
|
|
||||||
class OrderViewSet(viewsets.ModelViewSet):
|
class OrderViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
serializer_class = OrderSerializer
|
serializer_class = OrderSerializer
|
||||||
permission_classes = [permissions.IsAuthenticated]
|
permission_classes = [permissions.IsAuthenticated]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue