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 current discount for current plan.

Lauryn Menarda8172591cab4
diff --git a/analytics/tests/test_support_views.py b/analytics/tests/test_support_views.py
index cbdcbc908fc..c0cf035fd04 100644
--- a/analytics/tests/test_support_views.py
+++ b/analytics/tests/test_support_views.py
@@ -615,10 +615,11 @@ class TestSupportEndpoint(ZulipTestCase):
)
def test_attach_discount(self) -> None:
- cordelia = self.example_user("cordelia")
lear_realm = get_realm("lear")
- self.login_user(cordelia)
+ customer = self.create_customer_and_plan(lear_realm, True)
+ cordelia = self.example_user("cordelia")
+ self.login_user(cordelia)
result = self.client_post(
"/activity/support", {"realm_id": f"{lear_realm.id}", "discount": "25"}
)
@@ -632,9 +633,26 @@ class TestSupportEndpoint(ZulipTestCase):
"/activity/support", {"realm_id": f"{lear_realm.id}", "discount": "25"}
)
self.assert_in_success_response(["Discount for lear changed to 25% from 0%"], result)
- customer = get_customer_by_realm(lear_realm)
- assert customer is not None
+
+ customer.refresh_from_db()
+ plan = get_current_plan_by_customer(customer)
+ assert plan is not None
self.assertEqual(customer.default_discount, Decimal(25))
+ self.assertEqual(plan.discount, Decimal(25))
+
+ result = self.client_get("/activity/support", {"q": "lear"})
+ self.assert_in_success_response(
+ [
+ "<b>Plan name</b>: Zulip Cloud Standard",
+ "<b>Status</b>: Active",
+ "<b>Discount</b>: 25%",
+ "<b>Billing schedule</b>: Monthly",
+ "<b>Licenses</b>: 2/10 (Manual)",
+ "<b>Price per license</b>: $6.0",
+ "<b>Next invoice date</b>: 02 February 2016",
+ ],
+ result,
+ )
def test_change_sponsorship_status(self) -> None:
lear_realm = get_realm("lear")
diff --git a/analytics/views/support.py b/analytics/views/support.py
index d16ef66e483..93eae91fec2 100644
--- a/analytics/views/support.py
+++ b/analytics/views/support.py
@@ -56,6 +56,7 @@ if settings.BILLING_ENABLED:
RemoteServerBillingSession,
SupportType,
SupportViewRequest,
+ format_discount_percentage,
)
from corporate.lib.support import (
PlanData,
@@ -364,6 +365,7 @@ def support(
context["get_realm_admin_emails_as_string"] = get_realm_admin_emails_as_string
context["get_discount"] = get_customer_discount_for_support_view
context["get_org_type_display_name"] = get_org_type_display_name
+ context["format_discount"] = format_discount_percentage
context["realm_icon_url"] = realm_icon_url
context["Confirmation"] = Confirmation
context["sorted_realm_types"] = sorted(
@@ -513,6 +515,7 @@ def remote_servers_support(
context["remote_realms_support_data"] = realm_support_data
context["get_plan_type_name"] = get_plan_type_string
context["get_org_type_display_name"] = get_org_type_display_name
+ context["format_discount"] = format_discount_percentage
context["SPONSORED_PLAN_TYPE"] = RemoteZulipServer.PLAN_TYPE_COMMUNITY
return render(
diff --git a/templates/analytics/current_plan_details.html b/templates/analytics/current_plan_details.html
index 818cf7f8c9e..897ba0c5a82 100644
--- a/templates/analytics/current_plan_details.html
+++ b/templates/analytics/current_plan_details.html
@@ -10,6 +10,9 @@
{% if plan_data.current_plan.tier == plan_data.current_plan.TIER_SELF_HOSTED_COMMUNITY %}
<!-- Any data below doesn't makes sense for sponsored organizations. -->
{% else %}
+{% if plan_data.current_plan.discount %}
+ <b>Discount</b>: {{ format_discount(plan_data.current_plan.discount) }}%<br />
+{% endif %}
{% if plan_data.is_legacy_plan %}
<b>End date</b>: {{ plan_data.current_plan.end_date.strftime('%d %B %Y') }}<br />
{% else %}
diff --git a/templates/analytics/realm_details.html b/templates/analytics/realm_details.html
index 9cc589818b8..caeca9f7d1d 100644
--- a/templates/analytics/realm_details.html
+++ b/templates/analytics/realm_details.html
@@ -113,6 +113,7 @@
<div class="current-plan-details">
{% with %}
{% set plan_data = plan_data[realm.id] %}
+ {% set format_discount = format_discount %}
{% include 'analytics/current_plan_details.html' %}
{% endwith %}
</div>
diff --git a/templates/analytics/remote_realm_details.html b/templates/analytics/remote_realm_details.html
index 76776eac222..8d6b788fbc8 100644
--- a/templates/analytics/remote_realm_details.html
+++ b/templates/analytics/remote_realm_details.html
@@ -27,6 +27,7 @@
<div class="remote-realm-information">
{% with %}
{% set plan_data = support_data[remote_realm.id].plan_data %}
+ {% set format_discount = format_discount %}
{% include 'analytics/current_plan_details.html' %}
{% endwith %}
</div>
diff --git a/templates/analytics/remote_server_support.html b/templates/analytics/remote_server_support.html
index 5a979ce133f..209157cb918 100644
--- a/templates/analytics/remote_server_support.html
+++ b/templates/analytics/remote_server_support.html
@@ -69,6 +69,7 @@
<div class="remote-server-information">
{% with %}
{% set plan_data = remote_servers_support_data[remote_server.id].plan_data %}
+ {% set format_discount = format_discount %}
{% include 'analytics/current_plan_details.html' %}
{% endwith %}
</div>
@@ -87,6 +88,7 @@
{% with %}
{% set support_data = remote_realms_support_data %}
{% set get_plan_type_name = get_plan_type_name %}
+ {% set format_discount = format_discount %}
{% include "analytics/remote_realm_details.html" %}
{% endwith %}
</div>
diff --git a/templates/analytics/support.html b/templates/analytics/support.html
index 01c5249c2c6..ab02df03a7e 100644
--- a/templates/analytics/support.html
+++ b/templates/analytics/support.html
@@ -49,7 +49,10 @@
</form>
<hr />
<div>
- {% include "analytics/realm_details.html" %}
+ {% with %}
+ {% set format_discount = format_discount %}
+ {% include "analytics/realm_details.html" %}
+ {% endwith %}
</div>
<hr />
</div>
@@ -57,7 +60,10 @@
{% for realm in realms %}
<div class="support-query-result">
- {% include "analytics/realm_details.html" %}
+ {% with %}
+ {% set format_discount = format_discount %}
+ {% include "analytics/realm_details.html" %}
+ {% endwith %}
</div>
{% endfor %}
@@ -106,7 +112,10 @@
{% if show_realm_details %}
<hr />
<div>
- {% include "analytics/realm_details.html" %}
+ {% with %}
+ {% set format_discount = format_discount %}
+ {% include "analytics/realm_details.html" %}
+ {% endwith %}
</div>
{% elif realm %}
<b>Realm</b>: {{ realm.string_id }}