forked from uncloud/uncloud
Allow to select billing period when registering VM
This commit is contained in:
parent
5559d600c7
commit
b31aa72f84
4 changed files with 25 additions and 5 deletions
|
|
@ -32,19 +32,23 @@ class VMProductViewSet(ProductViewSet):
|
|||
# if something goes wrong.
|
||||
@transaction.atomic
|
||||
def create(self, request):
|
||||
# Extract serializer data.
|
||||
serializer = VMProductSerializer(data=request.data, context={'request': request})
|
||||
serializer.is_valid(raise_exception=True)
|
||||
order_recurring_period = serializer.validated_data.pop("recurring_period")
|
||||
|
||||
# Create base order.
|
||||
order = Order.objects.create(
|
||||
recurring_period=RecurringPeriod.PER_MONTH,
|
||||
recurring_period=order_recurring_period,
|
||||
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)
|
||||
|
||||
# Add Product record to order (VM is mutable, allows to keep history in order).
|
||||
# XXX: Move this to some kind of on_create hook in parent Product class?
|
||||
order.add_record(vm.setup_fee,
|
||||
vm.recurring_price(order.recurring_period), vm.description)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue