support: Show current discount for current plan.

This should match any discount information shown for the remote
realm or server.
This commit is contained in:
Lauryn Menard
2023-12-15 17:16:39 +01:00
committed by Tim Abbott
parent be6c90f608
commit a8172591ca
7 changed files with 44 additions and 7 deletions

View File

@@ -615,10 +615,11 @@ class TestSupportEndpoint(ZulipTestCase):
) )
def test_attach_discount(self) -> None: def test_attach_discount(self) -> None:
cordelia = self.example_user("cordelia")
lear_realm = get_realm("lear") 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( result = self.client_post(
"/activity/support", {"realm_id": f"{lear_realm.id}", "discount": "25"} "/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"} "/activity/support", {"realm_id": f"{lear_realm.id}", "discount": "25"}
) )
self.assert_in_success_response(["Discount for lear changed to 25% from 0%"], result) 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(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: def test_change_sponsorship_status(self) -> None:
lear_realm = get_realm("lear") lear_realm = get_realm("lear")

View File

@@ -56,6 +56,7 @@ if settings.BILLING_ENABLED:
RemoteServerBillingSession, RemoteServerBillingSession,
SupportType, SupportType,
SupportViewRequest, SupportViewRequest,
format_discount_percentage,
) )
from corporate.lib.support import ( from corporate.lib.support import (
PlanData, PlanData,
@@ -364,6 +365,7 @@ def support(
context["get_realm_admin_emails_as_string"] = get_realm_admin_emails_as_string context["get_realm_admin_emails_as_string"] = get_realm_admin_emails_as_string
context["get_discount"] = get_customer_discount_for_support_view context["get_discount"] = get_customer_discount_for_support_view
context["get_org_type_display_name"] = get_org_type_display_name 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["realm_icon_url"] = realm_icon_url
context["Confirmation"] = Confirmation context["Confirmation"] = Confirmation
context["sorted_realm_types"] = sorted( context["sorted_realm_types"] = sorted(
@@ -513,6 +515,7 @@ def remote_servers_support(
context["remote_realms_support_data"] = realm_support_data context["remote_realms_support_data"] = realm_support_data
context["get_plan_type_name"] = get_plan_type_string context["get_plan_type_name"] = get_plan_type_string
context["get_org_type_display_name"] = get_org_type_display_name 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 context["SPONSORED_PLAN_TYPE"] = RemoteZulipServer.PLAN_TYPE_COMMUNITY
return render( return render(

View File

@@ -10,6 +10,9 @@
{% if plan_data.current_plan.tier == plan_data.current_plan.TIER_SELF_HOSTED_COMMUNITY %} {% if plan_data.current_plan.tier == plan_data.current_plan.TIER_SELF_HOSTED_COMMUNITY %}
<!-- Any data below doesn't makes sense for sponsored organizations. --> <!-- Any data below doesn't makes sense for sponsored organizations. -->
{% else %} {% 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 %} {% if plan_data.is_legacy_plan %}
<b>End date</b>: {{ plan_data.current_plan.end_date.strftime('%d %B %Y') }}<br /> <b>End date</b>: {{ plan_data.current_plan.end_date.strftime('%d %B %Y') }}<br />
{% else %} {% else %}

View File

@@ -113,6 +113,7 @@
<div class="current-plan-details"> <div class="current-plan-details">
{% with %} {% with %}
{% set plan_data = plan_data[realm.id] %} {% set plan_data = plan_data[realm.id] %}
{% set format_discount = format_discount %}
{% include 'analytics/current_plan_details.html' %} {% include 'analytics/current_plan_details.html' %}
{% endwith %} {% endwith %}
</div> </div>

View File

@@ -27,6 +27,7 @@
<div class="remote-realm-information"> <div class="remote-realm-information">
{% with %} {% with %}
{% set plan_data = support_data[remote_realm.id].plan_data %} {% set plan_data = support_data[remote_realm.id].plan_data %}
{% set format_discount = format_discount %}
{% include 'analytics/current_plan_details.html' %} {% include 'analytics/current_plan_details.html' %}
{% endwith %} {% endwith %}
</div> </div>

View File

@@ -69,6 +69,7 @@
<div class="remote-server-information"> <div class="remote-server-information">
{% with %} {% with %}
{% set plan_data = remote_servers_support_data[remote_server.id].plan_data %} {% set plan_data = remote_servers_support_data[remote_server.id].plan_data %}
{% set format_discount = format_discount %}
{% include 'analytics/current_plan_details.html' %} {% include 'analytics/current_plan_details.html' %}
{% endwith %} {% endwith %}
</div> </div>
@@ -87,6 +88,7 @@
{% with %} {% with %}
{% set support_data = remote_realms_support_data %} {% set support_data = remote_realms_support_data %}
{% set get_plan_type_name = get_plan_type_name %} {% set get_plan_type_name = get_plan_type_name %}
{% set format_discount = format_discount %}
{% include "analytics/remote_realm_details.html" %} {% include "analytics/remote_realm_details.html" %}
{% endwith %} {% endwith %}
</div> </div>

View File

@@ -49,7 +49,10 @@
</form> </form>
<hr /> <hr />
<div> <div>
{% include "analytics/realm_details.html" %} {% with %}
{% set format_discount = format_discount %}
{% include "analytics/realm_details.html" %}
{% endwith %}
</div> </div>
<hr /> <hr />
</div> </div>
@@ -57,7 +60,10 @@
{% for realm in realms %} {% for realm in realms %}
<div class="support-query-result"> <div class="support-query-result">
{% include "analytics/realm_details.html" %} {% with %}
{% set format_discount = format_discount %}
{% include "analytics/realm_details.html" %}
{% endwith %}
</div> </div>
{% endfor %} {% endfor %}
@@ -106,7 +112,10 @@
{% if show_realm_details %} {% if show_realm_details %}
<hr /> <hr />
<div> <div>
{% include "analytics/realm_details.html" %} {% with %}
{% set format_discount = format_discount %}
{% include "analytics/realm_details.html" %}
{% endwith %}
</div> </div>
{% elif realm %} {% elif realm %}
<b>Realm</b>: {{ realm.string_id }} <b>Realm</b>: {{ realm.string_id }}