model for classic plan pricing
This commit is contained in:
parent
96b667dd75
commit
3b8eea9c14
2 changed files with 98 additions and 2 deletions
|
@ -5,7 +5,13 @@ from django.urls import reverse
|
|||
from django.utils.text import slugify
|
||||
from django_prose_editor.fields import ProseEditorField
|
||||
|
||||
from .base import Category, ReusableText, ManagedServiceProvider, validate_image_size
|
||||
from .base import (
|
||||
Category,
|
||||
ReusableText,
|
||||
ManagedServiceProvider,
|
||||
validate_image_size,
|
||||
Currency,
|
||||
)
|
||||
from .providers import CloudProvider
|
||||
|
||||
|
||||
|
@ -97,10 +103,31 @@ class ServiceOffering(models.Model):
|
|||
)
|
||||
|
||||
|
||||
class PlanPrice(models.Model):
|
||||
plan = models.ForeignKey(
|
||||
"Plan", on_delete=models.CASCADE, related_name="plan_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 = ("plan", "currency")
|
||||
ordering = ["currency"]
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.plan.name} - {self.amount} {self.currency}"
|
||||
|
||||
|
||||
class Plan(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
description = ProseEditorField(blank=True, null=True)
|
||||
pricing = ProseEditorField(blank=True, null=True)
|
||||
plan_description = models.ForeignKey(
|
||||
ReusableText,
|
||||
on_delete=models.PROTECT,
|
||||
|
@ -122,6 +149,12 @@ class Plan(models.Model):
|
|||
def __str__(self):
|
||||
return f"{self.offering} - {self.name}"
|
||||
|
||||
def get_price(self, currency_code: str):
|
||||
price_obj = PlanPrice.objects.filter(plan=self, currency=currency_code).first()
|
||||
if price_obj:
|
||||
return price_obj.amount
|
||||
return None
|
||||
|
||||
|
||||
class ExternalLinkOffering(models.Model):
|
||||
offering = models.ForeignKey(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue