1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 21:29:38 +02:00

fix: Transfers should always total to zero (#1859)

This commit is contained in:
Tony Vincent 2025-02-17 17:42:30 +01:00 committed by GitHub
parent 8e339dcbe0
commit f35b70e936
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 4 deletions

View file

@ -154,7 +154,7 @@ module ApplicationHelper
def totals_by_currency(collection:, money_method:, separator: " | ", negate: false)
collection.group_by(&:currency)
.transform_values { |item| negate ? item.sum(&money_method) * -1 : item.sum(&money_method) }
.transform_values { |item| calculate_total(item, money_method, negate) }
.map { |_currency, money| format_money(money) }
.join(separator)
end
@ -166,4 +166,12 @@ module ApplicationHelper
cookies[:admin] == "true"
end
private
def calculate_total(item, money_method, negate)
items = item.reject { |i| i.respond_to?(:entryable) && i.entryable.transfer? }
total = items.sum(&money_method)
negate ? -total : total
end
end