Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

corporate: Add LicenseLedger fields for external licenses.

Sahil Batraf9e443213b0d
diff --git a/corporate/migrations/0048_licenseledger_external_licenses.py b/corporate/migrations/0048_licenseledger_external_licenses.py
new file mode 100644
index 00000000000..41900a57ab2
--- /dev/null
+++ b/corporate/migrations/0048_licenseledger_external_licenses.py
@@ -0,0 +1,20 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("corporate", "0047_customerplan_unique_never_started_plan_customer_and_more"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="licenseledger",
+ name="external_licenses",
+ field=models.IntegerField(db_default=0, default=0),
+ ),
+ migrations.AddField(
+ model_name="licenseledger",
+ name="external_licenses_at_next_renewal",
+ field=models.IntegerField(db_default=0, default=0),
+ ),
+ ]
diff --git a/corporate/models/licenses.py b/corporate/models/licenses.py
index 7964bda36c1..33c27f29587 100644
--- a/corporate/models/licenses.py
+++ b/corporate/models/licenses.py
@@ -43,8 +43,31 @@ class LicenseLedger(models.Model):
null=True, db_column="licenses_at_next_renewal"
)
+ # The number of licenses for users outside the realm's workplace_users_group at the time of
+ # ledger entry creation. These are billed at a discounted rate, so they are counted
+ # separately from workplace_licenses rather than being folded into it. The same "a license is
+ # valid till the end of the billing period" rule applies, so external_licenses never
+ # decreases for subsequent LicenseLedger entries in the same billing period.
+ #
+ # This counts the licenses actually billed at the discounted rate, so it is 0 for a plan
+ # that does not bill an external tier, even if the realm's workplace_users_group happens to
+ # exclude some users. Whether a plan bills an external tier is a property of the plan.
+ external_licenses = models.IntegerField(db_default=0, default=0)
+
+ # The number of external licenses the organization needs in the next billing cycle. Like
+ # workplace_licenses_at_next_renewal, this can increase or decrease for subsequent
+ # LicenseLedger entries in the same billing period.
+ external_licenses_at_next_renewal = models.IntegerField(db_default=0, default=0)
+
@override
def __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.workplace_licenses} purchased, {self.workplace_licenses_at_next_renewal} next cycle, {ledger_time} (id={self.id})"
+ external = ""
+ # Omitted entirely for plans without an external tier, which is the common case.
+ if self.external_licenses or self.external_licenses_at_next_renewal:
+ external = (
+ f", {self.external_licenses} external"
+ f" ({self.external_licenses_at_next_renewal} next cycle)"
+ )
+ return f"License {ledger_type}, {self.workplace_licenses} purchased, {self.workplace_licenses_at_next_renewal} next cycle{external}, {ledger_time} (id={self.id})"