introduce service plans

This commit is contained in:
Tobias Brunner 2025-01-28 10:41:39 +01:00
parent f69f7fb755
commit 70f4a02db9
No known key found for this signature in database
11 changed files with 362 additions and 20 deletions

View file

@ -1,5 +1,5 @@
from django import forms
from .models import Lead
from .models import Lead, Plan, PlanPrice
class LeadForm(forms.ModelForm):
@ -12,3 +12,38 @@ class LeadForm(forms.ModelForm):
"email": forms.EmailInput(attrs={"class": "form-control"}),
"phone": forms.TextInput(attrs={"class": "form-control"}),
}
class PlanForm(forms.ModelForm):
class Meta:
model = Plan
fields = ("name", "description", "is_default", "features", "order")
widgets = {
"description": forms.Textarea(attrs={"rows": 3}),
"features": forms.Textarea(attrs={"rows": 4}),
}
def clean(self):
cleaned_data = super().clean()
# If this is set as default, ensure no other plan for this service is default
if cleaned_data.get("is_default"):
service = self.instance.service
if service:
Plan.objects.filter(service=service).exclude(
pk=self.instance.pk
).update(is_default=False)
return cleaned_data
class PlanPriceForm(forms.ModelForm):
class Meta:
model = PlanPrice
fields = ("currency", "price")
def clean(self):
cleaned_data = super().clean()
currency = cleaned_data.get("currency")
price = cleaned_data.get("price")
if price and price < 0:
raise forms.ValidationError("Price cannot be negative")
return cleaned_data