forked from uncloud/uncloud
Add records to orders
This commit is contained in:
parent
8e41b894c0
commit
81bd54116a
4 changed files with 34 additions and 16 deletions
|
|
@ -40,8 +40,6 @@ class VMProduct(Product):
|
|||
blank=True,
|
||||
null=True)
|
||||
|
||||
description = "Virtual Machine"
|
||||
|
||||
# VM-specific. The name is only intended for customers: it's a pain te
|
||||
# remember IDs (speaking from experience as ungleich customer)!
|
||||
name = models.CharField(max_length=32)
|
||||
|
|
@ -55,6 +53,10 @@ class VMProduct(Product):
|
|||
else:
|
||||
raise Exception('Invalid recurring period for VM Product pricing.')
|
||||
|
||||
@property
|
||||
def description(self):
|
||||
return "Virtual machine '{}': {} core(s), {}GB memory".format(
|
||||
self.name, self.cores, self.ram_in_gb)
|
||||
|
||||
class VMWithOSProduct(VMProduct):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ class VMProductViewSet(ProductViewSet):
|
|||
return VMProduct.objects.filter(owner=self.request.user)
|
||||
|
||||
def create(self, request):
|
||||
# TODO: what if something blows-up midway?
|
||||
# => need a transaction
|
||||
|
||||
# Create base order.
|
||||
order = Order.objects.create(
|
||||
recurring_period=RecurringPeriod.PER_MONTH,
|
||||
|
|
@ -40,6 +43,10 @@ class VMProductViewSet(ProductViewSet):
|
|||
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).
|
||||
order.add_record(vm.setup_fee,
|
||||
vm.recurring_price(order.recurring_period), vm.description)
|
||||
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue