billing: Create is_realm_on_free_trial helper function.

This commit is contained in:
Vishnu KS
2020-11-11 18:39:30 +05:30
committed by Tim Abbott
parent 06b5f9feae
commit f55dbe33bb
2 changed files with 24 additions and 0 deletions

View File

@@ -785,6 +785,11 @@ def invoice_plans_as_needed(event_time: datetime = timezone_now()) -> None:
invoice_plan(plan, event_time) invoice_plan(plan, event_time)
def is_realm_on_free_trial(realm: Realm) -> bool:
plan = get_current_plan_by_realm(realm)
return plan is not None and plan.is_free_trial()
def attach_discount_to_realm( def attach_discount_to_realm(
realm: Realm, discount: Decimal, *, acting_user: Optional[UserProfile] realm: Realm, discount: Decimal, *, acting_user: Optional[UserProfile]
) -> None: ) -> None:

View File

@@ -35,6 +35,7 @@ from corporate.lib.stripe import (
get_realms_to_default_discount_dict, get_realms_to_default_discount_dict,
invoice_plan, invoice_plan,
invoice_plans_as_needed, invoice_plans_as_needed,
is_realm_on_free_trial,
make_end_of_cycle_updates_if_needed, make_end_of_cycle_updates_if_needed,
next_month, next_month,
process_initial_upgrade, process_initial_upgrade,
@@ -2969,6 +2970,24 @@ class BillingHelpersTest(ZulipTestCase):
}, },
) )
def test_is_realm_on_free_trial(self) -> None:
realm = get_realm("zulip")
self.assertFalse(is_realm_on_free_trial(realm))
customer = Customer.objects.create(realm=realm, stripe_customer_id="cus_12345")
plan = CustomerPlan.objects.create(
customer=customer,
status=CustomerPlan.ACTIVE,
billing_cycle_anchor=timezone_now(),
billing_schedule=CustomerPlan.ANNUAL,
tier=CustomerPlan.STANDARD,
)
self.assertFalse(is_realm_on_free_trial(realm))
plan.status = CustomerPlan.FREE_TRIAL
plan.save(update_fields=["status"])
self.assertTrue(is_realm_on_free_trial(realm))
class LicenseLedgerTest(StripeTestCase): class LicenseLedgerTest(StripeTestCase):
def test_add_plan_renewal_if_needed(self) -> None: def test_add_plan_renewal_if_needed(self) -> None: