Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

CRM: Fix sites rate + from float crashing (#5430)

hq11de10b78678b
diff --git a/extra/lib/plausible/customer_support/enterprise_plan.ex b/extra/lib/plausible/customer_support/enterprise_plan.ex
index 23dd366a2e..963b93eead 100644
--- a/extra/lib/plausible/customer_support/enterprise_plan.ex
+++ b/extra/lib/plausible/customer_support/enterprise_plan.ex
@@ -37,11 +37,11 @@ defmodule Plausible.CustomerSupport.EnterprisePlan do
cost_per_month =
Decimal.from_float(
- pv_rate +
- sites_rate +
- team_members_rate +
- api_calls_rate +
- features_rate
+ (pv_rate +
+ sites_rate +
+ team_members_rate +
+ api_calls_rate +
+ features_rate) * 1.0
)
|> Decimal.round(2)
@@ -88,7 +88,7 @@ defmodule Plausible.CustomerSupport.EnterprisePlan do
def pv_rate(:business, pvs) when pvs <= 1_000_000_000, do: 14_439
def pv_rate(:business, _), do: 14_439
- def sites_rate(n) when n <= 10, do: 0
+ def sites_rate(n) when n <= 50, do: 0
def sites_rate(n), do: n * 0.1
def team_members_rate(n) when n > 10, do: (n - 10) * 5
diff --git a/test/plausible/customer_support/enterprise_plan_test.exs b/test/plausible/customer_support/enterprise_plan_test.exs
index ccf2856536..abae9d8925 100644
--- a/test/plausible/customer_support/enterprise_plan_test.exs
+++ b/test/plausible/customer_support/enterprise_plan_test.exs
@@ -22,6 +22,21 @@ defmodule Plausible.CustomerSupport.EnterprisePlanTest do
assert result == Decimal.new("1038.00")
end
+ test "bugfix - from float" do
+ result =
+ EnterprisePlan.estimate(
+ :business,
+ "monthly",
+ 20_000_000,
+ 0,
+ 0,
+ 0,
+ ["sites_api"]
+ )
+
+ assert result == Decimal.new("738.00")
+ end
+
test "Bogdan's example (https://3.basecamp.com/5308029/buckets/26383192/card_tables/cards/8506177450#__recording_8689686259)" do
result =
EnterprisePlan.estimate(
@@ -98,8 +113,9 @@ defmodule Plausible.CustomerSupport.EnterprisePlanTest do
describe "sites_rate/1" do
test "calculates rate based on number of sites" do
assert EnterprisePlan.sites_rate(10) == 0
- assert EnterprisePlan.sites_rate(15) == 1.5
- assert EnterprisePlan.sites_rate(20) == 2.0
+ assert EnterprisePlan.sites_rate(45) == 0
+ assert EnterprisePlan.sites_rate(50) == 0
+ assert EnterprisePlan.sites_rate(60) == 6.0
end
end