support: Show annual revenue for active fixed price plans.

In the activity and support views, we want to see the annual
revenue for fixed price plans. While on billing pages, we do
not display this information as these plans are renegotiated
annually.

Adds get_annual_recurring_revenue_for_support_data function
to BillingSession class, so that we can get the fixed price
plan data for these views without changing the logic for
what is displayed on the billing pages.
This commit is contained in:
Lauryn Menard 2024-05-22 16:47:29 +02:00 committed by Tim Abbott
parent 3b73f19719
commit 4fcf7945b0
4 changed files with 19 additions and 13 deletions

View File

@ -191,18 +191,15 @@ def get_remote_activity_plan_data(
elif remote_realm is not None: elif remote_realm is not None:
renewal_cents = RemoteRealmBillingSession( renewal_cents = RemoteRealmBillingSession(
remote_realm=remote_realm remote_realm=remote_realm
).get_customer_plan_renewal_amount(plan, license_ledger) ).get_annual_recurring_revenue_for_support_data(plan, license_ledger)
current_rate = get_plan_rate_percentage(plan.discount) current_rate = get_plan_rate_percentage(plan.discount)
else: else:
assert remote_server is not None assert remote_server is not None
renewal_cents = RemoteServerBillingSession( renewal_cents = RemoteServerBillingSession(
remote_server=remote_server remote_server=remote_server
).get_customer_plan_renewal_amount(plan, license_ledger) ).get_annual_recurring_revenue_for_support_data(plan, license_ledger)
current_rate = get_plan_rate_percentage(plan.discount) current_rate = get_plan_rate_percentage(plan.discount)
if plan.billing_schedule == CustomerPlan.BILLING_SCHEDULE_MONTHLY:
renewal_cents *= 12
return RemoteActivityPlanData( return RemoteActivityPlanData(
current_status=plan.get_plan_status_as_text(), current_status=plan.get_plan_status_as_text(),
current_plan_name=plan.name, current_plan_name=plan.name,
@ -238,9 +235,7 @@ def get_estimated_arr_and_rate_by_realm() -> Tuple[Dict[str, int], Dict[str, str
assert latest_ledger_entry is not None assert latest_ledger_entry is not None
renewal_cents = RealmBillingSession( renewal_cents = RealmBillingSession(
realm=plan.customer.realm realm=plan.customer.realm
).get_customer_plan_renewal_amount(plan, latest_ledger_entry) ).get_annual_recurring_revenue_for_support_data(plan, latest_ledger_entry)
if plan.billing_schedule == CustomerPlan.BILLING_SCHEDULE_MONTHLY:
renewal_cents *= 12
annual_revenue[plan.customer.realm.string_id] = renewal_cents annual_revenue[plan.customer.realm.string_id] = renewal_cents
plan_rate[plan.customer.realm.string_id] = get_plan_rate_percentage(plan.discount) plan_rate[plan.customer.realm.string_id] = get_plan_rate_percentage(plan.discount)
return annual_revenue, plan_rate return annual_revenue, plan_rate

View File

@ -2305,6 +2305,19 @@ class BillingSession(ABC):
).first() ).first()
return None return None
def get_annual_recurring_revenue_for_support_data(
self, plan: CustomerPlan, last_ledger_entry: LicenseLedger
) -> int:
if plan.fixed_price is not None:
# For support and activity views, we want to show the annual
# revenue for the currently configured fixed price, which
# is the annual amount charged in cents.
return plan.fixed_price
revenue = self.get_customer_plan_renewal_amount(plan, last_ledger_entry)
if plan.billing_schedule == CustomerPlan.BILLING_SCHEDULE_MONTHLY:
revenue *= 12
return revenue
def get_customer_plan_renewal_amount( def get_customer_plan_renewal_amount(
self, self,
plan: CustomerPlan, plan: CustomerPlan,

View File

@ -186,7 +186,7 @@ def get_customer_sponsorship_data(customer: Customer) -> SponsorshipData:
def get_annual_invoice_count(billing_schedule: int) -> int: def get_annual_invoice_count(billing_schedule: int) -> int:
if billing_schedule == CustomerPlan.BILLING_SCHEDULE_MONTHLY: if billing_schedule == CustomerPlan.BILLING_SCHEDULE_MONTHLY:
return 12 return 12
else: else: # nocoverage
return 1 return 1
@ -283,13 +283,11 @@ def get_plan_data_for_support_view(
plan_data.is_current_plan_billable = billing_session.check_plan_tier_is_billable( plan_data.is_current_plan_billable = billing_session.check_plan_tier_is_billable(
plan_tier=plan_data.current_plan.tier plan_tier=plan_data.current_plan.tier
) )
annual_invoice_count = get_annual_invoice_count(plan_data.current_plan.billing_schedule)
if last_ledger_entry is not None: if last_ledger_entry is not None:
plan_data.annual_recurring_revenue = ( plan_data.annual_recurring_revenue = (
billing_session.get_customer_plan_renewal_amount( billing_session.get_annual_recurring_revenue_for_support_data(
plan_data.current_plan, last_ledger_entry plan_data.current_plan, last_ledger_entry
) )
* annual_invoice_count
) )
else: else:
plan_data.annual_recurring_revenue = 0 # nocoverage plan_data.annual_recurring_revenue = 0 # nocoverage

View File

@ -367,6 +367,6 @@ class ActivityTest(ZulipTestCase):
add_audit_log_data(realm.server, remote_realm=realm, realm_id=None) add_audit_log_data(realm.server, remote_realm=realm, realm_id=None)
self.login("iago") self.login("iago")
with self.assert_database_query_count(12): with self.assert_database_query_count(11):
result = self.client_get("/activity/remote") result = self.client_get("/activity/remote")
self.assertEqual(result.status_code, 200) self.assertEqual(result.status_code, 200)