models: Add plan_name attribute to CustomerPlan.

This commit is contained in:
Vishnu KS
2020-07-03 23:44:31 +05:30
committed by Tim Abbott
parent 38d01cd4db
commit f6cbb9177a
2 changed files with 10 additions and 5 deletions

View File

@@ -66,6 +66,15 @@ class CustomerPlan(models.Model):
# TODO maybe override setattr to ensure billing_cycle_anchor, etc are immutable
@property
def name(self) -> str:
return {
CustomerPlan.STANDARD: 'Zulip Standard',
CustomerPlan.PLUS: 'Zulip Plus',
CustomerPlan.ENTERPRISE: 'Zulip Enterprise',
}[self.tier]
def get_current_plan_by_customer(customer: Customer) -> Optional[CustomerPlan]:
return CustomerPlan.objects.filter(
customer=customer, status__lt=CustomerPlan.LIVE_STATUS_THRESHOLD).first()

View File

@@ -264,10 +264,6 @@ def billing_home(request: HttpRequest) -> HttpResponse:
if new_plan is not None: # nocoverage
plan = new_plan
assert(plan is not None) # for mypy
plan_name = {
CustomerPlan.STANDARD: 'Zulip Standard',
CustomerPlan.PLUS: 'Zulip Plus',
}[plan.tier]
free_trial = plan.status == CustomerPlan.FREE_TRIAL
downgrade_at_end_of_cycle = plan.status == CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE
switch_to_annual_at_end_of_cycle = plan.status == CustomerPlan.SWITCH_TO_ANNUAL_AT_END_OF_CYCLE
@@ -284,7 +280,7 @@ def billing_home(request: HttpRequest) -> HttpResponse:
payment_method = 'Billed by invoice'
context.update({
'plan_name': plan_name,
'plan_name': plan.name,
'has_active_plan': True,
'free_trial': free_trial,
'downgrade_at_end_of_cycle': downgrade_at_end_of_cycle,