VMs now properly set their pricing

This commit is contained in:
Nico Schottelius 2020-05-02 23:44:20 +02:00
parent c835c874d5
commit 99a18232aa
2 changed files with 11 additions and 11 deletions

View file

@ -845,15 +845,15 @@ class Order(models.Model):
super().save(*args, **kwargs) super().save(*args, **kwargs)
Bill.generate_for(self.starting_date.year, self.starting_date.month, self.owner) # Bill.generate_for(self.starting_date.year, self.starting_date.month, self.owner)
# Used by uncloud_pay tests. # # Used by uncloud_pay tests.
@property # @property
def bills(self): # def bills(self):
return Bill.objects.filter(order=self) # return Bill.objects.filter(order=self)
def __str__(self): def __str__(self):
return "Order {} created at {}, {}->{}, recurring period {}. Price one time {}, recurring {}".format( return "Order {} created at {}, {}->{}, recurring period {}. One time price {}, recurring price {}".format(
self.uuid, self.creation_date, self.uuid, self.creation_date,
self.starting_date, self.ending_date, self.starting_date, self.ending_date,
self.recurring_period, self.recurring_period,
@ -997,11 +997,10 @@ class Product(UncloudModel):
raise ValidationError("Cannot order without a billing address") raise ValidationError("Cannot order without a billing address")
self.order = Order.objects.create(owner=self.owner, self.order = Order.objects.create(owner=self.owner,
billing_address=billing_address) billing_address=billing_address,
one_time_price=self.one_time_price,
recurring_price=self.recurring_price)
print("in save op: {}".format(self))
print(self.order)
super().save(*args, **kwargs) super().save(*args, **kwargs)
# # Make sure we only create records on creation. # # Make sure we only create records on creation.

View file

@ -69,7 +69,7 @@ class VMProduct(Product):
cores = models.IntegerField() cores = models.IntegerField()
ram_in_gb = models.FloatField() ram_in_gb = models.FloatField()
# Default recurring price is PER_MONTH, see uncloud_pay.models.Product.
@property @property
def recurring_price(self): def recurring_price(self):
return self.cores * 3 + self.ram_in_gb * 4 return self.cores * 3 + self.ram_in_gb * 4
@ -79,6 +79,7 @@ class VMProduct(Product):
self.name, self.name,
self.cores, self.cores,
self.ram_in_gb) self.ram_in_gb)
@property @property
def description(self): def description(self):
return "Virtual machine '{}': {} core(s), {}GB memory".format( return "Virtual machine '{}': {} core(s), {}GB memory".format(