Skip to content

Commit

Permalink
support: Show annual revenue for active fixed price plans.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
laurynmm committed May 22, 2024
1 parent 39c6a01 commit d67eee3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions corporate/lib/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions corporate/lib/stripe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion corporate/lib/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion corporate/tests/test_activity_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit d67eee3

Please sign in to comment.