Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
billing: Create is_free_trial function in CustomerPlan model.
Vishnu KS06b5f9feaeaa
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex e0136259fa4..61219368604 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -136,7 +136,7 @@ def next_month(billing_cycle_anchor: datetime, dt: datetime) -> datetime:def start_of_next_billing_cycle(plan: CustomerPlan, event_time: datetime) -> datetime:- if plan.status == CustomerPlan.FREE_TRIAL:+ if plan.is_free_trial():assert plan.next_invoice_date is not None # for mypyreturn plan.next_invoice_date@@ -358,7 +358,7 @@ def make_end_of_cycle_updates_if_needed(licenses=last_ledger_entry.licenses_at_next_renewal,licenses_at_next_renewal=last_ledger_entry.licenses_at_next_renewal,)- if plan.status == CustomerPlan.FREE_TRIAL:+ if plan.is_free_trial():plan.invoiced_through = last_ledger_entryassert plan.next_invoice_date is not Noneplan.billing_cycle_anchor = plan.next_invoice_date.replace(microsecond=0)diff --git a/corporate/models.py b/corporate/models.pyindex 863488db954..e54aa016b44 100644--- a/corporate/models.py+++ b/corporate/models.py@@ -117,6 +117,9 @@ class CustomerPlan(models.Model):LicenseLedger.objects.filter(plan=self).order_by("id").last().licenses_at_next_renewal)+ def is_free_trial(self) -> bool:+ return self.status == CustomerPlan.FREE_TRIAL+def get_current_plan_by_customer(customer: Customer) -> Optional[CustomerPlan]:return CustomerPlan.objects.filter(diff --git a/corporate/views.py b/corporate/views.pyindex e0d3040b777..4c817901261 100644--- a/corporate/views.py+++ b/corporate/views.py@@ -300,7 +300,6 @@ def billing_home(request: HttpRequest) -> HttpResponse:if new_plan is not None: # nocoverageplan = new_planassert plan is not None # for mypy- free_trial = plan.status == CustomerPlan.FREE_TRIALdowngrade_at_end_of_cycle = plan.status == CustomerPlan.DOWNGRADE_AT_END_OF_CYCLEswitch_to_annual_at_end_of_cycle = (plan.status == CustomerPlan.SWITCH_TO_ANNUAL_AT_END_OF_CYCLE@@ -324,7 +323,7 @@ def billing_home(request: HttpRequest) -> HttpResponse:context.update(plan_name=plan.name,has_active_plan=True,- free_trial=free_trial,+ free_trial=plan.is_free_trial(),downgrade_at_end_of_cycle=downgrade_at_end_of_cycle,automanage_licenses=plan.automanage_licenses,switch_to_annual_at_end_of_cycle=switch_to_annual_at_end_of_cycle,@@ -391,7 +390,7 @@ def update_plan(assert plan.fixed_price is Nonedo_change_plan_status(plan, status)elif status == CustomerPlan.ENDED:- assert plan.status == CustomerPlan.FREE_TRIAL+ assert plan.is_free_trial()downgrade_now_without_creating_additional_invoices(user.realm)return json_success()