implement plan pricing
Some checks failed
Django Tests / test (push) Failing after 1m3s
Django Tests / test (pull_request) Failing after 1m3s

This commit is contained in:
Tobias Brunner 2025-06-20 17:40:38 +02:00
parent 96b667dd75
commit 61cabd1b1e
No known key found for this signature in database
7 changed files with 192 additions and 1257 deletions

View file

@ -4,10 +4,14 @@ from django.core.validators import URLValidator
from django.urls import reverse
from django.utils.text import slugify
from django_prose_editor.fields import ProseEditorField
from typing import TYPE_CHECKING, Optional
from .base import Category, ReusableText, ManagedServiceProvider, validate_image_size
from .base import Category, ReusableText, ManagedServiceProvider, validate_image_size, Currency
from .providers import CloudProvider
if TYPE_CHECKING:
from .services import PlanPrice
class Service(models.Model):
name = models.CharField(max_length=200)
@ -97,10 +101,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 +147,13 @@ class Plan(models.Model):
def __str__(self):
return f"{self.offering} - {self.name}"
def get_price(self, currency_code: str) -> Optional[float]:
from hub.services.models.services import PlanPrice
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(