billing: Create update_license_ledger_for_manual_plan.

This commit is contained in:
Vishnu KS
2020-12-30 23:26:57 +05:30
committed by Tim Abbott
parent 611866e3d6
commit 20d2e00cf9
2 changed files with 84 additions and 0 deletions

View File

@@ -629,6 +629,30 @@ def process_initial_upgrade(
do_change_plan_type(realm, Realm.STANDARD, acting_user=user)
def update_license_ledger_for_manual_plan(
plan: CustomerPlan,
event_time: datetime,
licenses: Optional[int] = None,
licenses_at_next_renewal: Optional[int] = None,
) -> None:
if licenses is not None:
assert get_latest_seat_count(plan.customer.realm) <= licenses
assert licenses > plan.licenses()
LicenseLedger.objects.create(
plan=plan, event_time=event_time, licenses=licenses, licenses_at_next_renewal=licenses
)
elif licenses_at_next_renewal is not None:
assert get_latest_seat_count(plan.customer.realm) <= licenses_at_next_renewal
LicenseLedger.objects.create(
plan=plan,
event_time=event_time,
licenses=plan.licenses(),
licenses_at_next_renewal=licenses_at_next_renewal,
)
else:
raise AssertionError("Pass licenses or licenses_at_next_renewal")
def update_license_ledger_for_automanaged_plan(
realm: Realm, plan: CustomerPlan, event_time: datetime
) -> None: