stripe: Don't create `LicenseLedger` entries for non-live plans.

This commit is contained in:
Aman Agrawal 2023-12-06 06:43:18 +00:00 committed by Tim Abbott
parent fec155ea9c
commit 30f7d5e8df
1 changed files with 14 additions and 15 deletions

View File

@ -1209,21 +1209,20 @@ class BillingSession(ABC):
plan = CustomerPlan.objects.create( plan = CustomerPlan.objects.create(
customer=customer, next_invoice_date=next_invoice_date, **plan_params customer=customer, next_invoice_date=next_invoice_date, **plan_params
) )
# HACK: In theory, we should be creating these ledger
# entries only outside the code path for if plan.status < CustomerPlan.LIVE_STATUS_THRESHOLD:
# should_schedule_upgrade_for_legacy_remote_server; they # LicenseLedger entries are way for us to charge customer and track their license usage.
# exist mainly to help the existing code display accurate # So, we should only create these entries for live plans.
# information about the second NEVER_STARTED plan on the ledger_entry = LicenseLedger.objects.create(
# billing page. plan=plan,
ledger_entry = LicenseLedger.objects.create( is_renewal=True,
plan=plan, event_time=event_time,
is_renewal=True, licenses=billed_licenses,
event_time=event_time, licenses_at_next_renewal=billed_licenses,
licenses=billed_licenses, )
licenses_at_next_renewal=billed_licenses, plan.invoiced_through = ledger_entry
) plan.save(update_fields=["invoiced_through"])
plan.invoiced_through = ledger_entry
plan.save(update_fields=["invoiced_through"])
self.write_to_audit_log( self.write_to_audit_log(
event_type=AuditLogEventType.CUSTOMER_PLAN_CREATED, event_type=AuditLogEventType.CUSTOMER_PLAN_CREATED,
event_time=event_time, event_time=event_time,