portico: Fix logic for scheduled upgrade context variables.

Renames context variables used for the pricing model template for
when the customer has a current plan that has an upgrade to a new
plan tier scheduled.

Fixes the "Upgrade scheduled" note that was being shown when an
annual fixed-price plan has a subsequent fixed-price plan scheduled
to start when the current plan ends.

Prep for adding a complimentary access plan for Zulip Cloud.
This commit is contained in:
Lauryn Menard
2025-01-20 17:00:05 +01:00
committed by Tim Abbott
parent 5f8959397b
commit 9fdaa9de0c
2 changed files with 24 additions and 17 deletions

View File

@@ -78,8 +78,8 @@ class PlansPageContext:
is_new_customer: bool = False
on_free_tier: bool = False
customer_plan: CustomerPlan | None = None
is_legacy_server_with_scheduled_upgrade: bool = False
legacy_server_new_plan: CustomerPlan | None = None
has_scheduled_upgrade: bool = False
scheduled_upgrade_plan: CustomerPlan | None = None
requested_sponsorship_plan: str | None = None
billing_base_url: str = ""
@@ -123,6 +123,7 @@ def plans_view(request: HttpRequest) -> HttpResponse:
context.on_free_tier = not context.is_sponsored
else:
context.on_free_trial = is_customer_on_free_trial(context.customer_plan)
# TODO implement a complimentary access plan/tier for Zulip Cloud.
context.is_new_customer = (
not context.on_free_tier and context.customer_plan is None and not context.is_sponsored
@@ -178,16 +179,19 @@ def remote_realm_plans_page(
and not context.is_sponsored
)
context.on_free_trial = is_customer_on_free_trial(context.customer_plan)
context.is_legacy_server_with_scheduled_upgrade = (
context.customer_plan.status == CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END
)
if context.is_legacy_server_with_scheduled_upgrade:
if context.customer_plan.status == CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END:
assert context.customer_plan.end_date is not None
context.legacy_server_new_plan = CustomerPlan.objects.get(
context.scheduled_upgrade_plan = CustomerPlan.objects.get(
customer=customer,
billing_cycle_anchor=context.customer_plan.end_date,
status=CustomerPlan.NEVER_STARTED,
)
# Fixed-price plan renewals have a CustomerPlan.status of
# SWITCH_PLAN_TIER_AT_PLAN_END, so we check to see if there is
# a CustomerPlan.tier change for the scheduled upgrade note.
context.has_scheduled_upgrade = (
context.customer_plan.tier != context.scheduled_upgrade_plan.tier
)
if billing_session.customer_plan_exists():
# Free trial is disabled for existing customers.
@@ -243,16 +247,19 @@ def remote_server_plans_page(
CustomerPlan.TIER_SELF_HOSTED_BASE,
)
context.on_free_trial = is_customer_on_free_trial(context.customer_plan)
context.is_legacy_server_with_scheduled_upgrade = (
context.customer_plan.status == CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END
)
if context.is_legacy_server_with_scheduled_upgrade:
if context.customer_plan.status == CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_END:
assert context.customer_plan.end_date is not None
context.legacy_server_new_plan = CustomerPlan.objects.get(
context.scheduled_upgrade_plan = CustomerPlan.objects.get(
customer=customer,
billing_cycle_anchor=context.customer_plan.end_date,
status=CustomerPlan.NEVER_STARTED,
)
# Fixed-price plan renewals have a CustomerPlan.status of
# SWITCH_PLAN_TIER_AT_PLAN_END, so we check to see if there is
# a CustomerPlan.tier change for the scheduled upgrade note.
context.has_scheduled_upgrade = (
context.customer_plan.tier != context.scheduled_upgrade_plan.tier
)
if billing_session.customer_plan_exists():
# Free trial is disabled for existing customers.