support: Use shared template for current plan details on support views.

Moves the section in support views for any current plan details
to a new template: `templates/analytics/current_plan_details.html`.

Also, updates the PlanData dataclass to have a boolean that checks
if the current plan tier is the self-hosted legacy plan.
This commit is contained in:
Lauryn Menard 2023-12-06 18:09:34 +01:00 committed by Tim Abbott
parent 771f8a3542
commit d079a13760
6 changed files with 31 additions and 28 deletions

View File

@ -198,7 +198,7 @@ class TestSupportEndpoint(ZulipTestCase):
'<option value="deactivated" >Deactivated</option>',
'scrub-realm-button">',
'data-string-id="lear"',
"<b>Name</b>: Zulip Cloud Standard",
"<b>Plan name</b>: Zulip Cloud Standard",
"<b>Status</b>: Active",
"<b>Billing schedule</b>: Annual",
"<b>Licenses</b>: 2/10 (Manual)",

View File

@ -18,6 +18,7 @@ class PlanData:
current_plan: Optional["CustomerPlan"] = None
licenses: Optional[int] = None
licenses_used: Optional[int] = None
is_legacy_plan: bool = False
def get_support_url(realm: Realm) -> str:
@ -55,5 +56,9 @@ def get_current_plan_data_for_support_view(billing_session: BillingSession) -> P
plan_data.current_plan = new_plan # nocoverage
plan_data.licenses = last_ledger_entry.licenses
plan_data.licenses_used = billing_session.current_count_for_billed_licenses()
assert plan_data.current_plan is not None # for mypy
plan_data.is_legacy_plan = (
plan_data.current_plan.tier == CustomerPlan.TIER_SELF_HOSTED_LEGACY
)
return plan_data

View File

@ -0,0 +1,15 @@
<h4>📅 Current plan information:</h4>
<b>Plan name</b>: {{ plan_data.current_plan.name }}<br />
<b>Status</b>: {{ plan_data.current_plan.get_plan_status_as_text() }}<br />
{% if plan_data.is_legacy_plan %}
<b>End date</b>: {{ plan_data.current_plan.end_date.strftime('%d %B %Y') }}<br />
{% else %}
<b>Billing schedule</b>: {% if plan_data.current_plan.billing_schedule == plan_data.current_plan.BILLING_SCHEDULE_ANNUAL %}Annual{% else %}Monthly{% endif %}<br />
<b>Licenses</b>: {{ plan_data.licenses_used }}/{{ plan_data.licenses }} ({% if plan_data.current_plan.automanage_licenses %}Automatic{% else %}Manual{% endif %})<br />
{% if plan_data.current_plan.price_per_license %}
<b>Price per license</b>: ${{ plan_data.current_plan.price_per_license/100 }}<br />
{% elif plan_data.current_plan.fixed_price %}
<b>Fixed price</b>: ${{ plan_data.current_plan.fixed_price/100 }}<br />
{% endif %}
<b>Next invoice date</b>: {{ plan_data.current_plan.next_invoice_date.strftime('%d %B %Y') }}<br />
{% endif %}

View File

@ -108,19 +108,13 @@
<button type="submit" class="btn btn-default support-submit-button">Update</button>
{% endif %}
</form>
{% if plan_data[realm.id].current_plan %}
<div class="current-plan-details">
<h3>📅 Current plan</h3>
<b>Name</b>: {{ plan_data[realm.id].current_plan.name }}<br />
<b>Status</b>: {{plan_data[realm.id].current_plan.get_plan_status_as_text()}}<br />
<b>Billing schedule</b>: {% if plan_data[realm.id].current_plan.billing_schedule == plan_data[realm.id].current_plan.BILLING_SCHEDULE_ANNUAL %}Annual{% else %}Monthly{% endif %}<br />
<b>Licenses</b>: {{ plan_data[realm.id].licenses_used }}/{{ plan_data[realm.id].licenses }} ({% if plan_data[realm.id].current_plan.automanage_licenses %}Automatic{% else %}Manual{% endif %})<br />
{% if plan_data[realm.id].current_plan.price_per_license %}
<b>Price per license</b>: ${{ plan_data[realm.id].current_plan.price_per_license/100 }}<br />
{% else %}
<b>Fixed price</b>: ${{ plan_data[realm.id].current_plan.fixed_price/100 }}<br />
{% endif %}
<b>Next invoice date</b>: {{ plan_data[realm.id].current_plan.next_invoice_date.strftime('%d %B %Y') }}<br />
{% with %}
{% set plan_data = plan_data[realm.id] %}
{% include 'analytics/current_plan_details.html' %}
{% endwith %}
</div>
<form method="POST" class="billing-modality-form">

View File

@ -93,21 +93,10 @@
{% if plan_data[remote_server.id].current_plan %}
<div class="remote-server-information">
<h4>📅 Current plan information:</h4>
<b>Plan name</b>: {{ plan_data[remote_server.id].current_plan.name }}<br />
<b>Status</b>: {{plan_data[remote_server.id].current_plan.get_plan_status_as_text()}}<br />
{% if plan_data[remote_server.id].current_plan.tier != 101 %}
<b>Billing schedule</b>: {% if plan_data[remote_server.id].current_plan.billing_schedule == plan_data[remote_server.id].current_plan.BILLING_SCHEDULE_ANNUAL %}Annual{% else %}Monthly{% endif %}<br />
<b>Licenses</b>: {{ plan_data[remote_server.id].licenses_used }}/{{ plan_data[remote_server.id].licenses }} ({% if plan_data[remote_server.id].current_plan.automanage_licenses %}Automatic{% else %}Manual{% endif %})<br />
{% if plan_data[remote_server.id].current_plan.price_per_license %}
<b>Price per license</b>: ${{ plan_data[remote_server.id].current_plan.price_per_license/100 }}<br />
{% elif plan_data[remote_server.id].current_plan.fixed_price %}
<b>Fixed price</b>: ${{ plan_data[remote_server.id].current_plan.fixed_price/100 }}<br />
{% endif %}
<b>Next invoice date</b>: {{ plan_data[remote_server.id].current_plan.next_invoice_date.strftime('%d %B %Y') }}<br />
{% else %}
<b>End date</b>: {{ plan_data[remote_server.id].current_plan.end_date.strftime('%d %B %Y') }}<br />
{% endif %}
{% with %}
{% set plan_data = plan_data[remote_server.id] %}
{% include 'analytics/current_plan_details.html' %}
{% endwith %}
</div>
<form method="POST" class="remote-server-form">

View File

@ -189,7 +189,7 @@ tr.admin td:first-child {
.current-plan-details {
position: relative;
top: -15px;
top: -45px;
}
.approve-sponsorship-form {