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:
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")

View File

@@ -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(