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,12 +1209,10 @@ 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
# billing page.
ledger_entry = LicenseLedger.objects.create( ledger_entry = LicenseLedger.objects.create(
plan=plan, plan=plan,
is_renewal=True, is_renewal=True,
@ -1224,6 +1222,7 @@ class BillingSession(ABC):
) )
plan.invoiced_through = ledger_entry plan.invoiced_through = ledger_entry
plan.save(update_fields=["invoiced_through"]) 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,