From 4fcf7945b0f970d1cbcd7e3589dbb9658657f8e8 Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Wed, 22 May 2024 16:47:29 +0200 Subject: [PATCH] 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. --- corporate/lib/activity.py | 11 +++-------- corporate/lib/stripe.py | 13 +++++++++++++ corporate/lib/support.py | 6 ++---- corporate/tests/test_activity_views.py | 2 +- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/corporate/lib/activity.py b/corporate/lib/activity.py index 0a1da331a9..90a6bf1aa4 100644 --- a/corporate/lib/activity.py +++ b/corporate/lib/activity.py @@ -191,18 +191,15 @@ def get_remote_activity_plan_data( elif remote_realm is not None: renewal_cents = RemoteRealmBillingSession( 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) else: assert remote_server is not None renewal_cents = RemoteServerBillingSession( 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) - if plan.billing_schedule == CustomerPlan.BILLING_SCHEDULE_MONTHLY: - renewal_cents *= 12 - return RemoteActivityPlanData( current_status=plan.get_plan_status_as_text(), 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 renewal_cents = RealmBillingSession( realm=plan.customer.realm - ).get_customer_plan_renewal_amount(plan, latest_ledger_entry) - if plan.billing_schedule == CustomerPlan.BILLING_SCHEDULE_MONTHLY: - renewal_cents *= 12 + ).get_annual_recurring_revenue_for_support_data(plan, latest_ledger_entry) annual_revenue[plan.customer.realm.string_id] = renewal_cents plan_rate[plan.customer.realm.string_id] = get_plan_rate_percentage(plan.discount) return annual_revenue, plan_rate diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index 57709ebc4d..67536936d8 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -2305,6 +2305,19 @@ class BillingSession(ABC): ).first() 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( self, plan: CustomerPlan, diff --git a/corporate/lib/support.py b/corporate/lib/support.py index ac04c30ab7..1acfd0c566 100644 --- a/corporate/lib/support.py +++ b/corporate/lib/support.py @@ -186,7 +186,7 @@ def get_customer_sponsorship_data(customer: Customer) -> SponsorshipData: def get_annual_invoice_count(billing_schedule: int) -> int: if billing_schedule == CustomerPlan.BILLING_SCHEDULE_MONTHLY: return 12 - else: + else: # nocoverage 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_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: 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 ) - * annual_invoice_count ) else: plan_data.annual_recurring_revenue = 0 # nocoverage diff --git a/corporate/tests/test_activity_views.py b/corporate/tests/test_activity_views.py index 0bd21d05eb..058f0974df 100644 --- a/corporate/tests/test_activity_views.py +++ b/corporate/tests/test_activity_views.py @@ -367,6 +367,6 @@ class ActivityTest(ZulipTestCase): add_audit_log_data(realm.server, remote_realm=realm, realm_id=None) self.login("iago") - with self.assert_database_query_count(12): + with self.assert_database_query_count(11): result = self.client_get("/activity/remote") self.assertEqual(result.status_code, 200)