From d67eee3efa45cd33945e1b8b2ed8c32b632cb0b4 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 | 6 +++--- corporate/lib/stripe.py | 10 ++++++++++ corporate/lib/support.py | 2 +- corporate/tests/test_activity_views.py | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/corporate/lib/activity.py b/corporate/lib/activity.py index 0a1da331a9845e..d5344e565f2d4c 100644 --- a/corporate/lib/activity.py +++ b/corporate/lib/activity.py @@ -191,13 +191,13 @@ 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: @@ -238,7 +238,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) + ).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 diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index 57709ebc4d9d24..62a75933337d3a 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -2305,6 +2305,16 @@ def get_next_plan(self, plan: CustomerPlan) -> Optional[CustomerPlan]: ).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 + return self.get_customer_plan_renewal_amount(plan, last_ledger_entry) + def get_customer_plan_renewal_amount( self, plan: CustomerPlan, diff --git a/corporate/lib/support.py b/corporate/lib/support.py index f45d6d61b566ed..b1d83dc672958e 100644 --- a/corporate/lib/support.py +++ b/corporate/lib/support.py @@ -281,7 +281,7 @@ def get_plan_data_for_support_view( 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 diff --git a/corporate/tests/test_activity_views.py b/corporate/tests/test_activity_views.py index 0bd21d05ebffa8..058f0974df38fc 100644 --- a/corporate/tests/test_activity_views.py +++ b/corporate/tests/test_activity_views.py @@ -367,6 +367,6 @@ def add_audit_log_data( 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)