Fix a few errors on preview billing rework
Another WIP commit to sync with laptop, do not forget to rebase!
This commit is contained in:
parent
e319d1d151
commit
be2b0a8855
4 changed files with 25 additions and 8 deletions
|
@ -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)
|
||||
|
|
21
uncloud/uncloud_pay/migrations/0011_auto_20200229_1459.py
Normal file
21
uncloud/uncloud_pay/migrations/0011_auto_20200229_1459.py
Normal file
|
@ -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',
|
||||
),
|
||||
]
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue