Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

fix: Update budget percentage determination method (#440)

Alessio Cappae8e727d76e49
diff --git a/app/models/budget_category.rb b/app/models/budget_category.rb
index dcecbb252e..d4136d172f 100644
--- a/app/models/budget_category.rb
+++ b/app/models/budget_category.rb
@@ -70,9 +70,10 @@ class BudgetCategory < ApplicationRecord
end
def percent_of_budget_spent
- return 0 unless budgeted_spending > 0
-
- (actual_spending / budgeted_spending) * 100
+ return 0 if budgeted_spending == 0 && actual_spending == 0
+ return 0 if budgeted_spending > 0 && actual_spending == 0
+ return 100 if budgeted_spending == 0 && actual_spending > 0
+ (actual_spending.to_f / budgeted_spending) * 100 if budgeted_spending > 0 && actual_spending > 0
end
def bar_width_percent