mirror of https://github.com/zulip/zulip.git
billing: Create is_free_trial function in CustomerPlan model.
This commit is contained in:
parent
44d8368003
commit
06b5f9feae
|
@ -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 mypy
|
||||
return 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_entry
|
||||
assert plan.next_invoice_date is not None
|
||||
plan.billing_cycle_anchor = plan.next_invoice_date.replace(microsecond=0)
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -300,7 +300,6 @@ def billing_home(request: HttpRequest) -> HttpResponse:
|
|||
if new_plan is not None: # nocoverage
|
||||
plan = new_plan
|
||||
assert plan is not None # for mypy
|
||||
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
|
||||
|
@ -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 None
|
||||
do_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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue