billing: Create downgrade_at_the_end_of_billing_cycle.

This commit is contained in:
Vishnu KS 2020-08-13 16:36:05 +05:30 committed by Tim Abbott
parent b8b2e443bc
commit dbaea757ae
2 changed files with 7 additions and 1 deletions

View File

@ -637,6 +637,11 @@ def downgrade_now_without_creating_additional_invoices(realm: Realm) -> None:
plan.next_invoice_date = next_invoice_date(plan)
plan.save(update_fields=["invoiced_through", "next_invoice_date"])
def downgrade_at_the_end_of_billing_cycle(realm: Realm) -> None:
plan = get_current_plan_by_realm(realm)
assert(plan is not None)
do_change_plan_status(plan, CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE)
def void_all_open_invoices(realm: Realm) -> int:
customer = get_customer_by_realm(realm)
if customer is None:

View File

@ -20,6 +20,7 @@ from corporate.lib.stripe import (
BillingError,
do_change_plan_status,
do_replace_payment_source,
downgrade_at_the_end_of_billing_cycle,
downgrade_now_without_creating_additional_invoices,
get_latest_seat_count,
make_end_of_cycle_updates_if_needed,
@ -317,7 +318,7 @@ def change_plan_status(request: HttpRequest, user: UserProfile,
do_change_plan_status(plan, status)
elif status == CustomerPlan.DOWNGRADE_AT_END_OF_CYCLE:
assert(plan.status == CustomerPlan.ACTIVE)
do_change_plan_status(plan, status)
downgrade_at_the_end_of_billing_cycle(user.realm)
elif status == CustomerPlan.SWITCH_TO_ANNUAL_AT_END_OF_CYCLE:
assert(plan.billing_schedule == CustomerPlan.MONTHLY)
assert(plan.status == CustomerPlan.ACTIVE)