Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
corporate: Rename LicenseLedger licenses fields for workplace users.
Sahil Batrafb60368c7ce8
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex fc4a6448b03..de9ad179528 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -334,7 +334,7 @@ def get_amount_to_credit_for_plan_tier_change(next_renewal_date = start_of_next_billing_cycle(current_plan, plan_change_date)- last_renewal_amount = last_renewal_ledger.licenses * current_plan.price_per_license+ last_renewal_amount = last_renewal_ledger.workplace_licenses * current_plan.price_per_licenselast_renewal_date = last_renewal_ledger.event_timeprorated_fraction = 1 - (plan_change_date - last_renewal_date) / (@@ -986,8 +986,8 @@ class BillingSession(ABC):plan=plan,is_renewal=is_renewal,event_time=event_time,- licenses=licenses,- licenses_at_next_renewal=licenses_at_next_renewal,+ workplace_licenses=licenses,+ workplace_licenses_at_next_renewal=licenses_at_next_renewal,)# Customer plan offers are always for negotiated, annual, fixed-price plans.@@ -2126,8 +2126,8 @@ class BillingSession(ABC):)# Update license_at_next_renewal as per new paid plan.assert last_ledger_entry is not None- last_ledger_entry.licenses_at_next_renewal = billable_licenses- last_ledger_entry.save(update_fields=["licenses_at_next_renewal"])+ last_ledger_entry.workplace_licenses_at_next_renewal = billable_licenses+ last_ledger_entry.save(update_fields=["workplace_licenses_at_next_renewal"])complimentary_access_plan.status = CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_ENDcomplimentary_access_plan.save(update_fields=["status"])elif complimentary_access_plan is not None: # nocoverage@@ -2386,7 +2386,7 @@ class BillingSession(ABC):)last_ledger_entry = LicenseLedger.objects.filter(plan=plan).order_by("-id").first()assert last_ledger_entry is not None- licenses_at_next_renewal = last_ledger_entry.licenses_at_next_renewal+ licenses_at_next_renewal = last_ledger_entry.workplace_licenses_at_next_renewalassert licenses_at_next_renewal is not Noneassert plan.next_invoice_date is not Nonenext_billing_cycle = plan.next_invoice_date@@ -2487,7 +2487,7 @@ class BillingSession(ABC):event_in_next_billing_cycle = next_billing_cycle <= event_timeif event_in_next_billing_cycle and last_ledger_entry is not None:- licenses_at_next_renewal = last_ledger_entry.licenses_at_next_renewal+ licenses_at_next_renewal = last_ledger_entry.workplace_licenses_at_next_renewalassert licenses_at_next_renewal is not Noneif plan.end_date == next_billing_cycle and plan.status == CustomerPlan.ACTIVE:@@ -2718,10 +2718,10 @@ class BillingSession(ABC):if plan.end_date == get_next_billing_cycle_for_plan(plan):return 0return get_amount_due_fixed_price_plan(plan.fixed_price, plan.billing_schedule)- if last_ledger_entry.licenses_at_next_renewal is None:+ if last_ledger_entry.workplace_licenses_at_next_renewal is None:return 0 # nocoverageassert plan.price_per_license is not None # for mypy- return plan.price_per_license * last_ledger_entry.licenses_at_next_renewal+ return plan.price_per_license * last_ledger_entry.workplace_licenses_at_next_renewaldef get_billing_context_from_plan(self,@@ -2739,8 +2739,8 @@ class BillingSession(ABC):switch_to_monthly_at_end_of_cycle = (plan.status == CustomerPlan.SWITCH_TO_MONTHLY_AT_END_OF_CYCLE)- licenses = last_ledger_entry.licenses- licenses_at_next_renewal = last_ledger_entry.licenses_at_next_renewal+ licenses = last_ledger_entry.workplace_licenses+ licenses_at_next_renewal = last_ledger_entry.workplace_licenses_at_next_renewalassert licenses_at_next_renewal is not Nonemin_licenses_for_plan = self.min_licenses_for_plan(plan.tier)billable_license_count = self.get_current_billed_license_count()@@ -3284,13 +3284,13 @@ class BillingSession(ABC):"Unable to update licenses manually. Your plan is on automatic license management."))- if last_ledger_entry.licenses == licenses:+ if last_ledger_entry.workplace_licenses == licenses:raise JsonableError(_("Your plan is already on {licenses} licenses in the current billing period.").format(licenses=licenses))- if last_ledger_entry.licenses > licenses:+ if last_ledger_entry.workplace_licenses > licenses:raise JsonableError(_("You cannot decrease the licenses in the current billing period."))@@ -3321,7 +3321,7 @@ class BillingSession(ABC):"Cannot change the licenses for next billing cycle for a plan that is being downgraded."))- if last_ledger_entry.licenses_at_next_renewal == licenses_at_next_renewal:+ if last_ledger_entry.workplace_licenses_at_next_renewal == licenses_at_next_renewal:raise JsonableError(_("Your plan is already scheduled to renew with {licenses_at_next_renewal} licenses."@@ -3344,13 +3344,16 @@ class BillingSession(ABC):assert invoice is not None# Don't allow customer to reduce licenses for next billing cycle if they have paid invoice.if invoice.status == Invoice.PAID:- assert last_ledger_entry.licenses_at_next_renewal is not None- if last_ledger_entry.licenses_at_next_renewal > licenses_at_next_renewal:+ assert last_ledger_entry.workplace_licenses_at_next_renewal is not None+ if (+ last_ledger_entry.workplace_licenses_at_next_renewal+ > licenses_at_next_renewal+ ):raise JsonableError(_("You’ve already purchased {licenses_at_next_renewal} licenses for the next billing period.").format(- licenses_at_next_renewal=last_ledger_entry.licenses_at_next_renewal+ licenses_at_next_renewal=last_ledger_entry.workplace_licenses_at_next_renewal))else:@@ -3405,7 +3408,9 @@ class BillingSession(ABC):)assert current_plan_last_ledger is not None- old_plan_licenses_at_next_renewal = current_plan_last_ledger.licenses_at_next_renewal+ old_plan_licenses_at_next_renewal = (+ current_plan_last_ledger.workplace_licenses_at_next_renewal+ )assert old_plan_licenses_at_next_renewal is not Nonelicenses_for_new_plan = self.get_billable_licenses_for_customer(current_plan.customer,@@ -3493,7 +3498,7 @@ class BillingSession(ABC):else:assert plan.price_per_license is not None # needed for mypyinvoice_item_params["unit_amount_decimal"] = Decimal(plan.price_per_license)- invoice_item_params["quantity"] = ledger_entry.licenses+ invoice_item_params["quantity"] = ledger_entry.workplace_licensesinvoice_item_params["description"] = f"{plan.name} - renewal"return invoice_item_params@@ -3534,7 +3539,7 @@ class BillingSession(ABC):)unit_amount = int(plan.price_per_license * proration_fraction + 0.5)invoice_item_params["unit_amount_decimal"] = Decimal(unit_amount)- invoice_item_params["quantity"] = ledger_entry.licenses - licenses_base+ invoice_item_params["quantity"] = ledger_entry.workplace_licenses - licenses_baseinvoice_item_params["description"] = f"Additional {plan.name} license"return invoice_item_params@@ -3546,7 +3551,9 @@ class BillingSession(ABC):) -> stripe.params.InvoiceItemCreateParams:current_quantity = invoice_item.get("quantity")assert current_quantity is not None- invoice_item["quantity"] = current_quantity + (ledger_entry.licenses - licenses_base)+ invoice_item["quantity"] = current_quantity + (+ ledger_entry.workplace_licenses - licenses_base+ )return invoice_itemdef invoice_plan(self, plan: CustomerPlan, event_time: datetime) -> None:@@ -3579,7 +3586,7 @@ class BillingSession(ABC):licenses_base = Noneelse:assert plan.invoiced_through is not None- licenses_base = plan.invoiced_through.licenses+ licenses_base = plan.invoiced_through.workplace_licensesinvoiced_through_id = plan.invoiced_through.id# Mark the plan for start of invoicing process.@@ -3607,7 +3614,7 @@ class BillingSession(ABC):if ledger_entry.is_renewal or (plan.fixed_price is Noneand licenses_base is not None- and ledger_entry.licenses != licenses_base+ and ledger_entry.workplace_licenses != licenses_base):create_invoice_item = True@@ -3662,7 +3669,7 @@ class BillingSession(ABC):current_tracked_date = ledger_entry.event_time.date()# Update license base per ledger_entry.- licenses_base = ledger_entry.licenses+ licenses_base = ledger_entry.workplace_licensesplan.invoiced_through = ledger_entryplan.save(update_fields=["invoiced_through"])@@ -4126,14 +4133,16 @@ class BillingSession(ABC):plan.tier,event_time=event_time,)- licenses = max(current_plan_licenses_at_next_renewal, last_ledger_entry.licenses)+ licenses = max(+ current_plan_licenses_at_next_renewal, last_ledger_entry.workplace_licenses+ )else:licenses_at_next_renewal = self.get_billable_licenses_for_customer(plan.customer,plan.tier,event_time=event_time,)- licenses = max(licenses_at_next_renewal, last_ledger_entry.licenses)+ licenses = max(licenses_at_next_renewal, last_ledger_entry.workplace_licenses)self.create_license_ledger_entry(plan=plan,diff --git a/corporate/lib/support.py b/corporate/lib/support.pyindex 405b1791203..76ab76bd571 100644--- a/corporate/lib/support.py+++ b/corporate/lib/support.py@@ -314,7 +314,7 @@ def get_plan_data_for_support_view(plan_data.licenses = Noneplan_data.annual_recurring_revenue = 0else:- plan_data.licenses = last_ledger_entry.licenses+ plan_data.licenses = last_ledger_entry.workplace_licensesplan_data.annual_recurring_revenue = (billing_session.get_annual_recurring_revenue_for_support_data(plan_data.current_plan, last_ledger_entrydiff --git a/corporate/lib/test_stripe_class.py b/corporate/lib/test_stripe_class.pyindex 74927236694..3db71a5c388 100644--- a/corporate/lib/test_stripe_class.py+++ b/corporate/lib/test_stripe_class.py@@ -1054,6 +1054,6 @@ class StripeTestCase(ZulipTestCase):) -> LicenseLedger:ledger_entry = LicenseLedger.objects.filter(plan=plan).order_by("-id").first()assert ledger_entry is not None- self.assertEqual(ledger_entry.licenses, licenses)- self.assertEqual(ledger_entry.licenses_at_next_renewal, licenses_at_next_renewal)+ self.assertEqual(ledger_entry.workplace_licenses, licenses)+ self.assertEqual(ledger_entry.workplace_licenses_at_next_renewal, licenses_at_next_renewal)return ledger_entrydiff --git a/corporate/migrations/0001_squashed_0044_convert_ids_to_bigints.py b/corporate/migrations/0001_squashed_0044_convert_ids_to_bigints.pyindex 3538c8b2a31..5c53894519d 100644--- a/corporate/migrations/0001_squashed_0044_convert_ids_to_bigints.py+++ b/corporate/migrations/0001_squashed_0044_convert_ids_to_bigints.py@@ -226,8 +226,11 @@ class Migration(migrations.Migration):),("is_renewal", models.BooleanField(default=False)),("event_time", models.DateTimeField()),- ("licenses", models.IntegerField()),- ("licenses_at_next_renewal", models.IntegerField(null=True)),+ ("workplace_licenses", models.IntegerField(db_column="licenses")),+ (+ "workplace_licenses_at_next_renewal",+ models.IntegerField(db_column="licenses_at_next_renewal", null=True),+ ),("plan",models.ForeignKey(diff --git a/corporate/migrations/0004_licenseledger.py b/corporate/migrations/0004_licenseledger.pyindex e5e2e331a78..47a87d30116 100644--- a/corporate/migrations/0004_licenseledger.py+++ b/corporate/migrations/0004_licenseledger.py@@ -21,8 +21,11 @@ class Migration(migrations.Migration):),("is_renewal", models.BooleanField(default=False)),("event_time", models.DateTimeField()),- ("licenses", models.IntegerField()),- ("licenses_at_next_renewal", models.IntegerField(null=True)),+ ("workplace_licenses", models.IntegerField(db_column="licenses")),+ (+ "workplace_licenses_at_next_renewal",+ models.IntegerField(db_column="licenses_at_next_renewal", null=True),+ ),("plan",models.ForeignKey(diff --git a/corporate/models/licenses.py b/corporate/models/licenses.pyindex ce96622d7e3..7964bda36c1 100644--- a/corporate/models/licenses.py+++ b/corporate/models/licenses.py@@ -25,21 +25,26 @@ class LicenseLedger(models.Model):event_time = models.DateTimeField()- # The number of licenses ("seats") purchased by the organization at the time of ledger- # entry creation. Normally, to add a user the organization needs at least one spare license.- # Once a license is purchased, it is valid till the end of the billing period, irrespective- # of whether the license is used or not. So the value of licenses will never decrease for- # subsequent LicenseLedger entries in the same billing period.- licenses = models.IntegerField()-- # The number of licenses the organization needs in the next billing cycle. The value of- # licenses_at_next_renewal can increase or decrease for subsequent LicenseLedger entries in- # the same billing period. For plans on automatic license management this value is usually- # equal to the number of activated users in the organization.- licenses_at_next_renewal = models.IntegerField(null=True)+ # The number of workplace user licenses ("seats") purchased by the organization at the time+ # of ledger entry creation. Normally, to add a user the organization needs at least one spare+ # license. Once a license is purchased, it is valid till the end of the billing period,+ # irrespective of whether the license is used or not. So the value of workplace_licenses will+ # never decrease for subsequent LicenseLedger entries in the same billing period.+ #+ # The database columns for these fields reflect the historical field names, prior to+ # implementing two-tier billing.+ workplace_licenses = models.IntegerField(db_column="licenses")++ # The number of workplace user licenses the organization needs in the next billing cycle. The+ # value of workplace_licenses_at_next_renewal can increase or decrease for subsequent+ # LicenseLedger entries in the same billing period. For plans on automatic license management+ # this value is usually equal to the number of activated workplace users in the organization.+ workplace_licenses_at_next_renewal = models.IntegerField(+ null=True, db_column="licenses_at_next_renewal"+ )@overridedef __str__(self) -> str:ledger_type = "renewal" if self.is_renewal else "update"ledger_time = self.event_time.replace(tzinfo=None).isoformat(" ", "minutes")- return f"License {ledger_type}, {self.licenses} purchased, {self.licenses_at_next_renewal} next cycle, {ledger_time} (id={self.id})"+ return f"License {ledger_type}, {self.workplace_licenses} purchased, {self.workplace_licenses_at_next_renewal} next cycle, {ledger_time} (id={self.id})"diff --git a/corporate/models/plans.py b/corporate/models/plans.pyindex 45bcf809628..4abfdf332f2 100644--- a/corporate/models/plans.py+++ b/corporate/models/plans.py@@ -248,7 +248,7 @@ class CustomerPlan(AbstractCustomerPlan):ledger_entry = LicenseLedger.objects.filter(plan=self).order_by("id").last()assert ledger_entry is not None- return ledger_entry.licenses+ return ledger_entry.workplace_licensesdef licenses_at_next_renewal(self) -> int | None:from corporate.models.licenses import LicenseLedger@@ -260,7 +260,7 @@ class CustomerPlan(AbstractCustomerPlan):return Noneledger_entry = LicenseLedger.objects.filter(plan=self).order_by("id").last()assert ledger_entry is not None- return ledger_entry.licenses_at_next_renewal+ return ledger_entry.workplace_licenses_at_next_renewaldef is_free_trial(self) -> bool:return self.status == CustomerPlan.FREE_TRIALdiff --git a/corporate/tests/test_activity_views.py b/corporate/tests/test_activity_views.pyindex b27d85043ad..fa5e0e544ac 100644--- a/corporate/tests/test_activity_views.py+++ b/corporate/tests/test_activity_views.py@@ -159,8 +159,8 @@ class ActivityTest(ZulipTestCase):next_invoice_date=add_months(timezone_now(), 12),)LicenseLedger.objects.create(- licenses=10,- licenses_at_next_renewal=10,+ workplace_licenses=10,+ workplace_licenses_at_next_renewal=10,event_time=timezone_now(),is_renewal=True,plan=plan,@@ -270,8 +270,8 @@ class ActivityTest(ZulipTestCase):next_invoice_date=add_months(timezone_now(), 12),)LicenseLedger.objects.create(- licenses=10,- licenses_at_next_renewal=10,+ workplace_licenses=10,+ workplace_licenses_at_next_renewal=10,event_time=timezone_now(),is_renewal=True,plan=plan,diff --git a/corporate/tests/test_billing_lib.py b/corporate/tests/test_billing_lib.pyindex b4aa062be2f..ab5d33749ef 100644--- a/corporate/tests/test_billing_lib.py+++ b/corporate/tests/test_billing_lib.py@@ -730,8 +730,8 @@ class LicenseLedgerTest(StripeTestCase):self.assertEqual(ledger_entry.plan, plan)self.assertTrue(ledger_entry.is_renewal)self.assertEqual(ledger_entry.event_time, self.next_year)- self.assertEqual(ledger_entry.licenses, self.seat_count)- self.assertEqual(ledger_entry.licenses_at_next_renewal, self.seat_count)+ self.assertEqual(ledger_entry.workplace_licenses, self.seat_count)+ self.assertEqual(ledger_entry.workplace_licenses_at_next_renewal, self.seat_count)# Plan needs to renew, but we already added the plan_renewal ledger entrybilling_session.make_end_of_cycle_updates_if_needed(plan, self.next_year + timedelta(days=1)@@ -804,7 +804,10 @@ class LicenseLedgerTest(StripeTestCase):ledger_entries = list(LicenseLedger.objects.values_list(- "is_renewal", "event_time", "licenses", "licenses_at_next_renewal"+ "is_renewal",+ "event_time",+ "workplace_licenses",+ "workplace_licenses_at_next_renewal",).order_by("id"))self.assertEqual(@@ -873,7 +876,10 @@ class LicenseLedgerTest(StripeTestCase):ledger_entries = list(LicenseLedger.objects.values_list(- "is_renewal", "event_time", "licenses", "licenses_at_next_renewal"+ "is_renewal",+ "event_time",+ "workplace_licenses",+ "workplace_licenses_at_next_renewal",).order_by("id"))@@ -917,7 +923,7 @@ class LicenseLedgerTest(StripeTestCase):self.set_user_role(guest, UserProfile.ROLE_MODERATOR)ledger_entries = list(LicenseLedger.objects.values_list(- "is_renewal", "licenses", "licenses_at_next_renewal"+ "is_renewal", "workplace_licenses", "workplace_licenses_at_next_renewal").order_by("id"))self.assertEqual(@@ -1411,8 +1417,8 @@ class TestTestClasses(ZulipTestCase):ledger.refresh_from_db()self.assertEqual(ledger.plan, plan)- self.assertEqual(ledger.licenses, 50)- self.assertEqual(ledger.licenses_at_next_renewal, 60)+ self.assertEqual(ledger.workplace_licenses, 50)+ self.assertEqual(ledger.workplace_licenses_at_next_renewal, 60)realm.refresh_from_db()self.assertEqual(realm.plan_type, Realm.PLAN_TYPE_STANDARD)@@ -1432,8 +1438,8 @@ class TestTestClasses(ZulipTestCase):ledger.refresh_from_db()self.assertEqual(ledger.plan, plan)- self.assertEqual(ledger.licenses, 20)- self.assertEqual(ledger.licenses_at_next_renewal, 30)+ self.assertEqual(ledger.workplace_licenses, 20)+ self.assertEqual(ledger.workplace_licenses_at_next_renewal, 30)realm.refresh_from_db()self.assertEqual(realm.plan_type, Realm.PLAN_TYPE_STANDARD)diff --git a/corporate/tests/test_remote_billing.py b/corporate/tests/test_remote_billing.pyindex 129f357c832..d2b5e840eb7 100644--- a/corporate/tests/test_remote_billing.py+++ b/corporate/tests/test_remote_billing.py@@ -1029,8 +1029,8 @@ class RemoteBillingAuthenticationTest(RemoteRealmBillingTestCase):plan=server_plan,is_renewal=True,event_time=timezone_now(),- licenses=initial_license_count,- licenses_at_next_renewal=initial_license_count,+ workplace_licenses=initial_license_count,+ workplace_licenses_at_next_renewal=initial_license_count,)self.server.plan_type = RemoteZulipServer.PLAN_TYPE_BUSINESSself.server.save(update_fields=["plan_type"])@@ -1114,8 +1114,8 @@ class RemoteBillingAuthenticationTest(RemoteRealmBillingTestCase):billable_licenses = billing_session.get_billable_licenses_for_customer(customer, plan.tier)assert license_ledger is not Noneself.assertNotEqual(initial_license_count, billable_licenses)- self.assertEqual(license_ledger.licenses, initial_license_count)- self.assertEqual(license_ledger.licenses_at_next_renewal, billable_licenses)+ self.assertEqual(license_ledger.workplace_licenses, initial_license_count)+ self.assertEqual(license_ledger.workplace_licenses_at_next_renewal, billable_licenses)self.assertFalse(license_ledger.is_renewal)@responses.activatediff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.pyindex e1703b19c74..99640907e4b 100644--- a/corporate/tests/test_stripe.py+++ b/corporate/tests/test_stripe.py@@ -69,8 +69,8 @@ class StripeTest(StripeTestCase):plan=plan,is_renewal=True,event_time=self.now,- licenses=licenses_purchased,- licenses_at_next_renewal=licenses_purchased,+ workplace_licenses=licenses_purchased,+ workplace_licenses_at_next_renewal=licenses_purchased,)def test_catch_stripe_errors(self) -> None:@@ -1072,8 +1072,8 @@ class StripeTest(StripeTestCase):plan=plan,is_renewal=True,event_time=self.now,- licenses=10,- licenses_at_next_renewal=10,+ workplace_licenses=10,+ workplace_licenses_at_next_renewal=10,)# No Invoice object exists for the plan.billing_session = RealmBillingSession(realm=realm)@@ -1244,7 +1244,6 @@ class StripeTest(StripeTestCase):with time_machine.travel(self.now, tick=False):self.billing_session.do_update_plan(update_plan_request)self.check_last_ledger_entry_license_counts(plan, 123, 125)-invoice_plans_as_needed(free_trial_end_date)customer_plan.refresh_from_db()realm.refresh_from_db()@@ -2521,11 +2520,17 @@ class StripeTest(StripeTestCase):self.assert_length(annual_ledger_entries, 2)self.assertEqual(annual_ledger_entries[0].is_renewal, True)self.assertEqual(- annual_ledger_entries.values_list("licenses", "licenses_at_next_renewal")[0], (20, 20)+ annual_ledger_entries.values_list(+ "workplace_licenses", "workplace_licenses_at_next_renewal"+ )[0],+ (20, 20),)self.assertEqual(annual_ledger_entries[1].is_renewal, False)self.assertEqual(- annual_ledger_entries.values_list("licenses", "licenses_at_next_renewal")[1], (25, 25)+ annual_ledger_entries.values_list(+ "workplace_licenses", "workplace_licenses_at_next_renewal"+ )[1],+ (25, 25),)audit_log = RealmAuditLog.objects.get(event_type=AuditLogEventType.CUSTOMER_SWITCHED_FROM_MONTHLY_TO_ANNUAL_PLAN@@ -2687,7 +2692,9 @@ class StripeTest(StripeTestCase):self.assert_length(annual_ledger_entries, 1)self.assertEqual(annual_ledger_entries[0].is_renewal, True)self.assertEqual(- annual_ledger_entries.values_list("licenses", "licenses_at_next_renewal")[0],+ annual_ledger_entries.values_list(+ "workplace_licenses", "workplace_licenses_at_next_renewal"+ )[0],(num_licenses, num_licenses),)self.assertEqual(annual_plan.invoiced_through, None)@@ -2840,11 +2847,17 @@ class StripeTest(StripeTestCase):self.assert_length(monthly_ledger_entries, 2)self.assertEqual(monthly_ledger_entries[0].is_renewal, True)self.assertEqual(- monthly_ledger_entries.values_list("licenses", "licenses_at_next_renewal")[0], (25, 25)+ monthly_ledger_entries.values_list(+ "workplace_licenses", "workplace_licenses_at_next_renewal"+ )[0],+ (25, 25),)self.assertEqual(monthly_ledger_entries[1].is_renewal, False)self.assertEqual(- monthly_ledger_entries.values_list("licenses", "licenses_at_next_renewal")[1], (25, 25)+ monthly_ledger_entries.values_list(+ "workplace_licenses", "workplace_licenses_at_next_renewal"+ )[1],+ (25, 25),)audit_log = RealmAuditLog.objects.get(event_type=AuditLogEventType.CUSTOMER_SWITCHED_FROM_ANNUAL_TO_MONTHLY_PLAN@@ -4028,8 +4041,8 @@ class StripeTest(StripeTestCase):plan=plan,is_renewal=True,event_time=timezone_now(),- licenses=9,- licenses_at_next_renewal=9,+ workplace_licenses=9,+ workplace_licenses_at_next_renewal=9,)realm.plan_type = Realm.PLAN_TYPE_STANDARDrealm.save(update_fields=["plan_type"])diff --git a/corporate/tests/test_support_views.py b/corporate/tests/test_support_views.pyindex 2e59aab7a76..54439d24af7 100644--- a/corporate/tests/test_support_views.py+++ b/corporate/tests/test_support_views.py@@ -76,8 +76,8 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):LicenseLedger.objects.filter(plan=complimentary_access_plan).order_by("-id").first())assert last_ledger_entry is not None- last_ledger_entry.licenses_at_next_renewal = billed_licenses- last_ledger_entry.save(update_fields=["licenses_at_next_renewal"])+ last_ledger_entry.workplace_licenses_at_next_renewal = billed_licenses+ last_ledger_entry.save(update_fields=["workplace_licenses_at_next_renewal"])complimentary_access_plan.status = CustomerPlan.SWITCH_PLAN_TIER_AT_PLAN_ENDcomplimentary_access_plan.save(update_fields=["status"])plan_params = {@@ -762,8 +762,8 @@ class TestSupportEndpoint(ZulipTestCase):next_invoice_date=add_months(now, months),)LicenseLedger.objects.create(- licenses=10,- licenses_at_next_renewal=10,+ workplace_licenses=10,+ workplace_licenses_at_next_renewal=10,event_time=now,is_renewal=True,plan=plan,diff --git a/corporate/views/plan_activity.py b/corporate/views/plan_activity.pyindex e7ff881bc14..6eb215f472c 100644--- a/corporate/views/plan_activity.py+++ b/corporate/views/plan_activity.py@@ -37,8 +37,8 @@ def get_plan_ledger(request: HttpRequest, plan_id: int) -> HttpResponse:return [format_optional_datetime(record.event_time),record.is_renewal,- record.licenses,- record.licenses_at_next_renewal,+ record.workplace_licenses,+ record.workplace_licenses_at_next_renewal,]rows = list(map(row, ledger_entries))diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.pyindex 889bc8b184e..61018b05738 100644--- a/zerver/lib/test_classes.py+++ b/zerver/lib/test_classes.py@@ -1988,8 +1988,8 @@ Output:plan=plan,is_renewal=True,event_time=timezone_now(),- licenses=licenses,- licenses_at_next_renewal=licenses_at_next_renewal,+ workplace_licenses=licenses,+ workplace_licenses_at_next_renewal=licenses_at_next_renewal,)realm.plan_type = Realm.PLAN_TYPE_STANDARDrealm.save(update_fields=["plan_type"])diff --git a/zerver/tests/test_invite.py b/zerver/tests/test_invite.pyindex 60e5e160b25..b212c67d856 100644--- a/zerver/tests/test_invite.py+++ b/zerver/tests/test_invite.py@@ -585,8 +585,8 @@ class InviteUserTest(InviteUserBase):result = self.invite(self.nonreg_email("alice"), ["Denmark"])self.assert_json_success(result)- ledger.licenses_at_next_renewal = get_latest_seat_count(user.realm)- ledger.save(update_fields=["licenses_at_next_renewal"])+ ledger.workplace_licenses_at_next_renewal = get_latest_seat_count(user.realm)+ ledger.save(update_fields=["workplace_licenses_at_next_renewal"])with self.settings(BILLING_ENABLED=True):result = self.invite(self.nonreg_email("bob"), ["Denmark"])self.assert_json_error_contains(@@ -594,9 +594,9 @@ class InviteUserTest(InviteUserBase):"Your organization does not have enough Zulip licenses. Invitations were not sent.",)- ledger.licenses_at_next_renewal = 50- ledger.licenses = get_latest_seat_count(user.realm) + 1- ledger.save(update_fields=["licenses", "licenses_at_next_renewal"])+ ledger.workplace_licenses_at_next_renewal = 50+ ledger.workplace_licenses = get_latest_seat_count(user.realm) + 1+ ledger.save(update_fields=["workplace_licenses", "workplace_licenses_at_next_renewal"])with self.settings(BILLING_ENABLED=True):invitee_emails = self.nonreg_email("bob") + "," + self.nonreg_email("alice")result = self.invite(invitee_emails, ["Denmark"])@@ -605,8 +605,8 @@ class InviteUserTest(InviteUserBase):"Your organization does not have enough Zulip licenses. Invitations were not sent.",)- ledger.licenses = get_latest_seat_count(user.realm)- ledger.save(update_fields=["licenses"])+ ledger.workplace_licenses = get_latest_seat_count(user.realm)+ ledger.save(update_fields=["workplace_licenses"])with self.settings(BILLING_ENABLED=True):result = self.invite(self.nonreg_email("bob"), ["Denmark"])self.assert_json_error_contains(diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.pyindex 205d9e795d3..efb174b626d 100644--- a/zerver/tests/test_signup.py+++ b/zerver/tests/test_signup.py@@ -2318,8 +2318,8 @@ class UserSignUpTest(ZulipTestCase):expected_group_direct_message_user_ids,)- ledger.licenses_at_next_renewal = 50- ledger.save(update_fields=["licenses_at_next_renewal"])+ ledger.workplace_licenses_at_next_renewal = 50+ ledger.save(update_fields=["workplace_licenses_at_next_renewal"])with self.settings(BILLING_ENABLED=True):form = HomepageForm({"email": self.nonreg_email("test")}, realm=realm)self.assertIn(@@ -2327,9 +2327,9 @@ class UserSignUpTest(ZulipTestCase):form.errors["email"][0],)- ledger.licenses = 50- ledger.licenses_at_next_renewal = 5- ledger.save(update_fields=["licenses", "licenses_at_next_renewal"])+ ledger.workplace_licenses = 50+ ledger.workplace_licenses_at_next_renewal = 5+ ledger.save(update_fields=["workplace_licenses", "workplace_licenses_at_next_renewal"])with self.settings(BILLING_ENABLED=True):form = HomepageForm({"email": self.nonreg_email("test")}, realm=realm)self.assertIn(@@ -2347,8 +2347,8 @@ class UserSignUpTest(ZulipTestCase):expected_group_direct_message_user_ids,)- ledger.licenses_at_next_renewal = 50- ledger.save(update_fields=["licenses_at_next_renewal"])+ ledger.workplace_licenses_at_next_renewal = 50+ ledger.save(update_fields=["workplace_licenses_at_next_renewal"])with self.settings(BILLING_ENABLED=True):form = HomepageForm({"email": self.nonreg_email("test")}, realm=realm)self.assertEqual(form.errors, {})diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.pyindex 3a25c7c2187..549f33b4606 100644--- a/zerver/tests/test_users.py+++ b/zerver/tests/test_users.py@@ -239,8 +239,8 @@ class PermissionTest(ZulipTestCase):"Your organization does not have enough Zulip licenses to change a guest user's role.",)- ledger.licenses = get_latest_seat_count(desdemona.realm) + 1- ledger.save(update_fields=["licenses"])+ ledger.workplace_licenses = get_latest_seat_count(desdemona.realm) + 1+ ledger.save(update_fields=["workplace_licenses"])with self.settings(BILLING_ENABLED=True):result = self.client_patch(f"/json/users/{polonius.id}", req)self.assert_json_error(@@ -248,8 +248,8 @@ class PermissionTest(ZulipTestCase):"Your organization does not have enough Zulip licenses to change a guest user's role.",)- ledger.licenses_at_next_renewal = get_latest_seat_count(desdemona.realm) + 1- ledger.save(update_fields=["licenses_at_next_renewal"])+ ledger.workplace_licenses_at_next_renewal = get_latest_seat_count(desdemona.realm) + 1+ ledger.save(update_fields=["workplace_licenses_at_next_renewal"])with self.settings(BILLING_ENABLED=True):result = self.client_patch(f"/json/users/{polonius.id}", req)self.assert_json_success(result)diff --git a/zilencer/management/commands/populate_billing_realms.py b/zilencer/management/commands/populate_billing_realms.pyindex 40c0c86160a..f0c53849674 100644--- a/zilencer/management/commands/populate_billing_realms.py+++ b/zilencer/management/commands/populate_billing_realms.py@@ -324,8 +324,8 @@ def create_plan_for_customer(customer: Customer, customer_profile: CustomerProfi)LicenseLedger.objects.create(- licenses=25,- licenses_at_next_renewal=25,+ workplace_licenses=25,+ workplace_licenses_at_next_renewal=25,event_time=timezone_now(),is_renewal=True,plan=customer_plan,