continued work on price model
This commit is contained in:
parent
6f41c8c344
commit
a6a15150ea
10 changed files with 500 additions and 1 deletions
|
@ -362,6 +362,19 @@ class Currency(models.TextChoices):
|
|||
USD = "USD", "US Dollar"
|
||||
|
||||
|
||||
class Term(models.TextChoices):
|
||||
MTH = "MTH", "per Month (30d)"
|
||||
DAY = "DAY", "per Day"
|
||||
HR = "HR", "per Hour"
|
||||
MIN = "MIN", "per Minute"
|
||||
|
||||
|
||||
class Unit(models.TextChoices):
|
||||
GIB = "GIB", "GiB"
|
||||
MIB = "MIB", "MiB"
|
||||
CPU = "CPU", "vCPU"
|
||||
|
||||
|
||||
class ComputePlanPrice(models.Model):
|
||||
compute_plan = models.ForeignKey(
|
||||
"ComputePlan", on_delete=models.CASCADE, related_name="prices"
|
||||
|
@ -392,6 +405,11 @@ class ComputePlan(models.Model):
|
|||
help_text="vCPU to Memory ratio. How much vCPU per GiB RAM is available?"
|
||||
)
|
||||
active = models.BooleanField(default=True, help_text="Is the plan active?")
|
||||
term = models.CharField(
|
||||
max_length=3,
|
||||
default=Term.MTH,
|
||||
choices=Term.choices,
|
||||
)
|
||||
|
||||
cloud_provider = models.ForeignKey(
|
||||
CloudProvider, on_delete=models.CASCADE, related_name="compute_plans"
|
||||
|
@ -413,6 +431,61 @@ class ComputePlan(models.Model):
|
|||
return None
|
||||
|
||||
|
||||
class StoragePlanPrice(models.Model):
|
||||
storage_plan = models.ForeignKey(
|
||||
"StoragePlan", on_delete=models.CASCADE, related_name="prices"
|
||||
)
|
||||
currency = models.CharField(
|
||||
max_length=3,
|
||||
choices=Currency.choices,
|
||||
)
|
||||
amount = models.DecimalField(
|
||||
max_digits=10,
|
||||
decimal_places=2,
|
||||
help_text="Price in the specified currency, excl. VAT",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("storage_plan", "currency")
|
||||
ordering = ["currency"]
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.storage_plan.name} - {self.amount} {self.currency}"
|
||||
|
||||
|
||||
class StoragePlan(models.Model):
|
||||
name = models.CharField(max_length=200)
|
||||
cloud_provider = models.ForeignKey(
|
||||
CloudProvider, on_delete=models.CASCADE, related_name="storage_plans"
|
||||
)
|
||||
term = models.CharField(
|
||||
max_length=3,
|
||||
default=Term.MTH,
|
||||
choices=Term.choices,
|
||||
)
|
||||
unit = models.CharField(
|
||||
max_length=3,
|
||||
default=Unit.GIB,
|
||||
choices=Unit.choices,
|
||||
)
|
||||
|
||||
valid_from = models.DateTimeField(blank=True, null=True)
|
||||
valid_to = models.DateTimeField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = ("cloud_provider", "term", "unit", "valid_from", "valid_to")
|
||||
ordering = ["name"]
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def get_price(self, currency_code: str):
|
||||
try:
|
||||
return self.prices.get(currency=currency_code).amount
|
||||
except ComputePlanPrice.DoesNotExist:
|
||||
return None
|
||||
|
||||
|
||||
class VSHNAppCatBaseFee(models.Model):
|
||||
vshn_appcat_price_config = models.ForeignKey(
|
||||
"VSHNAppCatPrice", on_delete=models.CASCADE, related_name="base_fees"
|
||||
|
@ -459,6 +532,11 @@ class VSHNAppCatPrice(models.Model):
|
|||
ha_replica_max = models.IntegerField(
|
||||
default=1, help_text="Maximum supported replicas"
|
||||
)
|
||||
term = models.CharField(
|
||||
max_length=3,
|
||||
default=Term.MTH,
|
||||
choices=Term.choices,
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.service.name} - {self.get_variable_unit_display()} based pricing"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue