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.

support: Show customer plan details in support page.

Vishnu KS1a1396d07ed4
diff --git a/analytics/tests/test_views.py b/analytics/tests/test_views.py
index aa704097681..2bafd65f25b 100644
--- a/analytics/tests/test_views.py
+++ b/analytics/tests/test_views.py
@@ -10,7 +10,8 @@ from analytics.lib.counts import COUNT_STATS, CountStat
from analytics.lib.time_utils import time_range
from analytics.models import FillState, RealmCount, UserCount, last_successful_fill
from analytics.views import rewrite_client_arrays, sort_by_totals, sort_client_labels
-from corporate.models import get_customer_by_realm
+from corporate.lib.stripe import add_months
+from corporate.models import Customer, CustomerPlan, LicenseLedger, get_customer_by_realm
from zerver.lib.actions import do_create_multiuse_invite_link, do_send_realm_reactivation_email
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import reset_emails_in_zulip_realm
@@ -443,7 +444,15 @@ class TestSupportEndpoint(ZulipTestCase):
'<option value="active" selected>Active</option>',
'<option value="deactivated" >Deactivated</option>',
'scrub-realm-button">',
- 'data-string-id="lear"'], result)
+ 'data-string-id="lear"',
+ '<b>Name</b>: Zulip Standard',
+ '<b>Status</b>: Active',
+ '<b>Billing schedule</b>: Annual',
+ '<b>Licenses</b>: 2/10 (Manual)',
+ '<b>Price per license</b>: $80.0',
+ '<b>Payment method</b>: Send invoice',
+ '<b>Next invoice date</b>: 02 January 2017',
+ ], result)
def check_preregistration_user_query_result(result: HttpResponse, email: str, invite: bool=False) -> None:
self.assert_in_success_response(['<span class="label">preregistration user</span>\n',
@@ -486,6 +495,14 @@ class TestSupportEndpoint(ZulipTestCase):
self.login('iago')
+ customer = Customer.objects.create(realm=get_realm("lear"), stripe_customer_id='cus_123')
+ now = datetime(2016, 1, 2, tzinfo=timezone.utc)
+ plan = CustomerPlan.objects.create(customer=customer, billing_cycle_anchor=now,
+ billing_schedule=CustomerPlan.ANNUAL, tier=CustomerPlan.STANDARD,
+ price_per_license=8000, next_invoice_date=add_months(now, 12))
+ LicenseLedger.objects.create(licenses=10, licenses_at_next_renewal=10, event_time=timezone_now(),
+ is_renewal=True, plan=plan)
+
result = self.client_get("/activity/support")
self.assert_in_success_response(['<input type="text" name="q" class="input-xxlarge search-query"'], result)
diff --git a/analytics/views.py b/analytics/views.py
index e2b04db6303..c2536dc9cc4 100644
--- a/analytics/views.py
+++ b/analytics/views.py
@@ -72,8 +72,11 @@ from zerver.views.invite import get_invitee_emails_set
if settings.BILLING_ENABLED:
from corporate.lib.stripe import (
attach_discount_to_realm,
+ get_current_plan_by_realm,
get_customer_by_realm,
get_discount_for_realm,
+ get_latest_seat_count,
+ make_end_of_cycle_updates_if_needed,
update_sponsorship_status,
)
@@ -1185,6 +1188,17 @@ def support(request: HttpRequest) -> HttpResponse:
for realm in realms:
realm.customer = get_customer_by_realm(realm)
+ current_plan = get_current_plan_by_realm(realm)
+ if current_plan is not None:
+ new_plan, last_ledger_entry = make_end_of_cycle_updates_if_needed(current_plan, timezone_now())
+ if last_ledger_entry is not None:
+ if new_plan is not None:
+ realm.current_plan = new_plan
+ else:
+ realm.current_plan = current_plan
+ realm.current_plan.licenses = last_ledger_entry.licenses
+ realm.current_plan.licenses_used = get_latest_seat_count(realm)
+
context["realms"] = realms
confirmations: List[Dict[str, Any]] = []
diff --git a/corporate/models.py b/corporate/models.py
index ec36259a6eb..0cf0c74056c 100644
--- a/corporate/models.py
+++ b/corporate/models.py
@@ -74,6 +74,14 @@ class CustomerPlan(models.Model):
CustomerPlan.ENTERPRISE: 'Zulip Enterprise',
}[self.tier]
+ def get_plan_status_as_text(self) -> str:
+ return {
+ self.ACTIVE: "Active",
+ self.DOWNGRADE_AT_END_OF_CYCLE: "Scheduled for downgrade at end of cycle",
+ self.FREE_TRIAL: "Free trial",
+ self.ENDED: "Ended",
+ self.NEVER_STARTED: "Never started"
+ }[self.status]
def get_current_plan_by_customer(customer: Customer) -> Optional[CustomerPlan]:
return CustomerPlan.objects.filter(
diff --git a/static/styles/portico/activity.scss b/static/styles/portico/activity.scss
index 2bdcb34b100..db7c0e338e5 100644
--- a/static/styles/portico/activity.scss
+++ b/static/styles/portico/activity.scss
@@ -84,11 +84,16 @@ tr.admin td:first-child {
top: -25px;
}
-.scrub-realm-form {
+.current-plan-details {
position: relative;
top: -50px;
}
+.scrub-realm-form {
+ position: relative;
+ top: -40px;
+}
+
.support-search-button {
border-color: hsl(0, 0%, 83%);
border-radius: 2px;
diff --git a/templates/analytics/realm_details.html b/templates/analytics/realm_details.html
index 5945065bb72..7a2e7bf9225 100644
--- a/templates/analytics/realm_details.html
+++ b/templates/analytics/realm_details.html
@@ -47,6 +47,23 @@
<input type="number" name="discount" value="{{ get_discount_for_realm(realm) }}" required>
<button type="submit" class="button rounded small support-submit-button">Update</button>
</form>
+{% if realm.current_plan %}
+<div class="current-plan-details">
+ <h3>📅 Current plan</h3>
+ <b>Name</b>: {{ realm.current_plan.name }}<br>
+ <b>Status</b>: {{realm.current_plan.get_plan_status_as_text()}}<br>
+ <b>Billing schedule</b>: {% if realm.current_plan.billing_schedule == realm.current_plan.ANNUAL %}Annual{% else %}Monthly{% endif %}<br>
+ <b>Licenses</b>: {{ realm.current_plan.licenses_used }}/{{ realm.current_plan.licenses }} ({% if realm.current_plan.automanage_licenses %}Automatic{% else %}Manual{% endif %})<br>
+ {% if realm.current_plan.price_per_license %}
+ <b>Price per license</b>: ${{ realm.current_plan.price_per_license/100 }}<br>
+ {% else %}
+ <b>Fixed price</b>: ${{ realm.current_plan.fixed_price/100 }}<br>
+ {% endif %}
+ <b>Payment method</b>: {% if realm.current_plan.charge_automatically %}Card{% else %}Send invoice{% endif %}<br>
+ <b>Next invoice date</b>: {{ realm.current_plan.next_invoice_date.strftime('%d %B %Y') }}<br>
+</div>
+{% endif %}
+
<form method="POST" class="scrub-realm-form">
{{ csrf_input }}
<input type="hidden" name="realm_id" value="{{ realm.id }}" />