mirror of https://github.com/zulip/zulip.git
billing: Rename next_renewal_date to start_of_next_billing_cycle.
This commit is contained in:
parent
3cfc3ca24b
commit
4430f78aa3
|
@ -83,7 +83,7 @@ def next_month(billing_cycle_anchor: datetime, dt: datetime) -> datetime:
|
||||||
'billing_cycle_anchor: %s, dt: %s' % (billing_cycle_anchor, dt))
|
'billing_cycle_anchor: %s, dt: %s' % (billing_cycle_anchor, dt))
|
||||||
|
|
||||||
# TODO take downgrade into account
|
# TODO take downgrade into account
|
||||||
def next_renewal_date(plan: CustomerPlan, event_time: datetime) -> datetime:
|
def start_of_next_billing_cycle(plan: CustomerPlan, event_time: datetime) -> datetime:
|
||||||
months_per_period = {
|
months_per_period = {
|
||||||
CustomerPlan.ANNUAL: 12,
|
CustomerPlan.ANNUAL: 12,
|
||||||
CustomerPlan.MONTHLY: 1,
|
CustomerPlan.MONTHLY: 1,
|
||||||
|
@ -220,7 +220,7 @@ def add_plan_renewal_to_license_ledger_if_needed(plan: CustomerPlan, event_time:
|
||||||
last_ledger_entry = LicenseLedger.objects.filter(plan=plan).order_by('-id').first()
|
last_ledger_entry = LicenseLedger.objects.filter(plan=plan).order_by('-id').first()
|
||||||
last_renewal = LicenseLedger.objects.filter(plan=plan, is_renewal=True) \
|
last_renewal = LicenseLedger.objects.filter(plan=plan, is_renewal=True) \
|
||||||
.order_by('-id').first().event_time
|
.order_by('-id').first().event_time
|
||||||
plan_renewal_date = next_renewal_date(plan, last_renewal)
|
plan_renewal_date = start_of_next_billing_cycle(plan, last_renewal)
|
||||||
if plan_renewal_date <= event_time:
|
if plan_renewal_date <= event_time:
|
||||||
return LicenseLedger.objects.create(
|
return LicenseLedger.objects.create(
|
||||||
plan=plan, is_renewal=True, event_time=plan_renewal_date,
|
plan=plan, is_renewal=True, event_time=plan_renewal_date,
|
||||||
|
@ -403,7 +403,7 @@ def invoice_plan(plan: CustomerPlan, event_time: datetime) -> None:
|
||||||
last_renewal = LicenseLedger.objects.filter(
|
last_renewal = LicenseLedger.objects.filter(
|
||||||
plan=plan, is_renewal=True, event_time__lte=ledger_entry.event_time) \
|
plan=plan, is_renewal=True, event_time__lte=ledger_entry.event_time) \
|
||||||
.order_by('-id').first().event_time
|
.order_by('-id').first().event_time
|
||||||
period_end = next_renewal_date(plan, ledger_entry.event_time)
|
period_end = start_of_next_billing_cycle(plan, ledger_entry.event_time)
|
||||||
proration_fraction = (period_end - ledger_entry.event_time) / (period_end - last_renewal)
|
proration_fraction = (period_end - ledger_entry.event_time) / (period_end - last_renewal)
|
||||||
price_args = {'unit_amount': int(plan.price_per_license * proration_fraction + .5),
|
price_args = {'unit_amount': int(plan.price_per_license * proration_fraction + .5),
|
||||||
'quantity': ledger_entry.licenses - licenses_base}
|
'quantity': ledger_entry.licenses - licenses_base}
|
||||||
|
@ -423,7 +423,8 @@ def invoice_plan(plan: CustomerPlan, event_time: datetime) -> None:
|
||||||
description=description,
|
description=description,
|
||||||
discountable=False,
|
discountable=False,
|
||||||
period = {'start': datetime_to_timestamp(ledger_entry.event_time),
|
period = {'start': datetime_to_timestamp(ledger_entry.event_time),
|
||||||
'end': datetime_to_timestamp(next_renewal_date(plan, ledger_entry.event_time))},
|
'end': datetime_to_timestamp(
|
||||||
|
start_of_next_billing_cycle(plan, ledger_entry.event_time))},
|
||||||
idempotency_key=idempotency_key,
|
idempotency_key=idempotency_key,
|
||||||
**price_args)
|
**price_args)
|
||||||
invoice_item_created = True
|
invoice_item_created = True
|
||||||
|
|
|
@ -21,7 +21,7 @@ from corporate.lib.stripe import STRIPE_PUBLISHABLE_KEY, \
|
||||||
process_initial_upgrade, sign_string, \
|
process_initial_upgrade, sign_string, \
|
||||||
unsign_string, BillingError, process_downgrade, do_replace_payment_source, \
|
unsign_string, BillingError, process_downgrade, do_replace_payment_source, \
|
||||||
MIN_INVOICED_LICENSES, DEFAULT_INVOICE_DAYS_UNTIL_DUE, \
|
MIN_INVOICED_LICENSES, DEFAULT_INVOICE_DAYS_UNTIL_DUE, \
|
||||||
next_renewal_date, renewal_amount, \
|
start_of_next_billing_cycle, renewal_amount, \
|
||||||
add_plan_renewal_to_license_ledger_if_needed
|
add_plan_renewal_to_license_ledger_if_needed
|
||||||
from corporate.models import Customer, CustomerPlan, \
|
from corporate.models import Customer, CustomerPlan, \
|
||||||
get_active_plan
|
get_active_plan
|
||||||
|
@ -172,7 +172,7 @@ def billing_home(request: HttpRequest) -> HttpResponse:
|
||||||
licenses = last_ledger_entry.licenses
|
licenses = last_ledger_entry.licenses
|
||||||
licenses_used = get_seat_count(user.realm)
|
licenses_used = get_seat_count(user.realm)
|
||||||
# Should do this in javascript, using the user's timezone
|
# Should do this in javascript, using the user's timezone
|
||||||
renewal_date = '{dt:%B} {dt.day}, {dt.year}'.format(dt=next_renewal_date(plan, now))
|
renewal_date = '{dt:%B} {dt.day}, {dt.year}'.format(dt=start_of_next_billing_cycle(plan, now))
|
||||||
renewal_cents = renewal_amount(plan, now)
|
renewal_cents = renewal_amount(plan, now)
|
||||||
# TODO: this is the case where the plan doesn't automatically renew
|
# TODO: this is the case where the plan doesn't automatically renew
|
||||||
if renewal_cents is None: # nocoverage
|
if renewal_cents is None: # nocoverage
|
||||||
|
|
Loading…
Reference in New Issue