diff --git a/uncloud/uncloud_pay/helpers.py b/uncloud/uncloud_pay/helpers.py index 248fbb4..aaa1e11 100644 --- a/uncloud/uncloud_pay/helpers.py +++ b/uncloud/uncloud_pay/helpers.py @@ -5,6 +5,8 @@ from rest_framework.viewsets import GenericViewSet from django.db.models import Q from .models import Bill, Payment, PaymentMethod, Order from django.utils import timezone +from django.core.exceptions import ObjectDoesNotExist +from dateutil.relativedelta import relativedelta def sum_amounts(entries): return reduce(lambda acc, entry: acc + entry.amount, entries, 0) diff --git a/uncloud/uncloud_pay/migrations/0011_auto_20200229_1459.py b/uncloud/uncloud_pay/migrations/0011_auto_20200229_1459.py new file mode 100644 index 0000000..e4edbb0 --- /dev/null +++ b/uncloud/uncloud_pay/migrations/0011_auto_20200229_1459.py @@ -0,0 +1,21 @@ +# Generated by Django 3.0.3 on 2020-02-29 14:59 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_pay', '0010_merge_20200228_1303'), + ] + + operations = [ + migrations.RemoveField( + model_name='order', + name='one_time_price', + ), + migrations.RemoveField( + model_name='order', + name='recurring_price', + ), + ] diff --git a/uncloud/uncloud_pay/serializers.py b/uncloud/uncloud_pay/serializers.py index 3b8cc47..eeab444 100644 --- a/uncloud/uncloud_pay/serializers.py +++ b/uncloud/uncloud_pay/serializers.py @@ -10,7 +10,7 @@ from uncloud_vm.models import VMProduct class BillSerializer(serializers.ModelSerializer): class Meta: model = Bill - fields = ['owner', 'amount', 'due_date', 'creation_date', + fields = ['owner', 'total', 'due_date', 'creation_date', 'starting_date', 'ending_date'] class PaymentSerializer(serializers.ModelSerializer): diff --git a/uncloud/uncloud_vm/views.py b/uncloud/uncloud_vm/views.py index c3704e1..2dec2ae 100644 --- a/uncloud/uncloud_vm/views.py +++ b/uncloud/uncloud_vm/views.py @@ -31,21 +31,15 @@ class VMProductViewSet(ProductViewSet): # Create base order. order = Order.objects.create( recurring_period=RecurringPeriod.PER_MONTH, - recurring_price=0, - one_time_price=0, owner=request.user ) + order.save() # Create VM. serializer = VMProductSerializer(data=request.data, context={'request': request}) serializer.is_valid(raise_exception=True) vm = serializer.save(owner=request.user, order=order) - # FIXME: commit everything (VM + order) at once. - order.recurring_price = vm.recurring_price(order.recurring_period) - order.one_time_price = 0 - order.save() - return Response(serializer.data)