Adapt recurring price of VM and Matrix to new scheme

This commit is contained in:
fnux 2020-04-13 12:00:59 +02:00
parent 14f59430bb
commit f5897ed4b1
2 changed files with 6 additions and 15 deletions

View file

@ -15,11 +15,9 @@ class MatrixServiceProduct(Product):
) )
domain = models.CharField(max_length=255, default='domain.tld') domain = models.CharField(max_length=255, default='domain.tld')
def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH): # Default recurring price is PER_MONT, see Product class.
if recurring_period == RecurringPeriod.PER_MONTH: def recurring_price(self):
return self.monthly_managment_fee return self.monthly_managment_fee
else:
raise Exception('Invalid recurring period for VM Product pricing.')
@staticmethod @staticmethod
def base_image(): def base_image():

View file

@ -71,16 +71,9 @@ class VMProduct(Product):
primary_disk = models.ForeignKey('VMDiskProduct', on_delete=models.CASCADE, null=True) primary_disk = models.ForeignKey('VMDiskProduct', on_delete=models.CASCADE, null=True)
def recurring_price(self, recurring_period=RecurringPeriod.PER_MONTH): # Default recurring price is PER_MONTH, see uncloud_pay.models.Product.
# TODO: move magic numbers in variables def recurring_price(self):
if recurring_period == RecurringPeriod.PER_MONTH: return self.cores * 3 + self.ram_in_gb * 4
return self.cores * 3 + self.ram_in_gb * 4
elif recurring_period == RecurringPeriod.PER_HOUR:
return self.cores * 4.0/(30 * 24) + self.ram_in_gb * 4.5/(30* 24)
elif recurring_period == RecurringPeriod.PER_YEAR:
return (self.cores * 2.5 + self.ram_in_gb * 3.5) * 12
else:
raise Exception('Invalid recurring period for VM Product pricing.')
def __str__(self): def __str__(self):
return "VM {} ({}): {} cores {} gb ram".format(self.uuid, return "VM {} ({}): {} cores {} gb ram".format(self.uuid,