stripe: Check for min_licenses when switching plan tier.

When we are upgrading a customer to a different plan tier, we should
check if switching plans would lead to different licenses due to
different minimum license requirement between plans.
This commit is contained in:
Aman Agrawal
2025-01-17 16:41:59 +05:30
committed by Tim Abbott
parent 10b2e2a092
commit 6e1bb56519
6 changed files with 57 additions and 37 deletions

View File

@@ -3164,7 +3164,17 @@ class BillingSession(ABC):
LicenseLedger.objects.filter(plan=current_plan).order_by("id").last()
)
assert current_plan_last_ledger is not None
licenses_for_new_plan = current_plan_last_ledger.licenses_at_next_renewal
old_plan_licenses_at_next_renewal = current_plan_last_ledger.licenses_at_next_renewal
assert old_plan_licenses_at_next_renewal is not None
licenses_for_new_plan = self.get_billable_licenses_for_customer(
current_plan.customer,
new_plan_tier,
old_plan_licenses_at_next_renewal,
)
if not new_plan.automanage_licenses: # nocoverage
licenses_for_new_plan = max(old_plan_licenses_at_next_renewal, licenses_for_new_plan)
assert licenses_for_new_plan is not None
LicenseLedger.objects.create(
plan=new_plan,