corporate: Fix 'get_next_billing_cycle' for scheduled fixed-price plan.

No renewal ledger entry exists for a scheduled fixed-price plan.

Earlier, when a customer with scheduled fixed-price plan
visited the billing page, the 'get_next_billing_cycle' function
raised an assertion error as no renewal ledger entry exists.

We don't need the ledger entry to determine the next billing
cycle in this case, so we move the code block which determines
the last_renewal time within the else conditional i.e. where it
is needed.

The scheduled plan has NEVER_STARTED status and the
next_invoice_date set to end date of the current plan.
We use this info to determine the next billing cycle.
This commit is contained in:
Prakhar Pratyush 2024-03-15 23:20:09 +05:30 committed by Tim Abbott
parent 1c48ed0a1c
commit 421400c651
1 changed files with 6 additions and 6 deletions

View File

@ -1994,15 +1994,10 @@ class BillingSession(ABC):
)
def get_next_billing_cycle(self, plan: CustomerPlan) -> datetime:
last_ledger_renewal = (
LicenseLedger.objects.filter(plan=plan, is_renewal=True).order_by("-id").first()
)
assert last_ledger_renewal is not None
last_renewal = last_ledger_renewal.event_time
if plan.status in (
CustomerPlan.FREE_TRIAL,
CustomerPlan.DOWNGRADE_AT_END_OF_FREE_TRIAL,
CustomerPlan.NEVER_STARTED,
):
assert plan.next_invoice_date is not None
next_billing_cycle = plan.next_invoice_date
@ -2010,6 +2005,11 @@ class BillingSession(ABC):
assert plan.end_date is not None
next_billing_cycle = plan.end_date
else:
last_ledger_renewal = (
LicenseLedger.objects.filter(plan=plan, is_renewal=True).order_by("-id").first()
)
assert last_ledger_renewal is not None
last_renewal = last_ledger_renewal.event_time
next_billing_cycle = start_of_next_billing_cycle(plan, last_renewal)
if plan.end_date is not None: