1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00

Fix Plaid cash balance double counting (#2222)
Some checks are pending
Publish Docker image / ci (push) Waiting to run
Publish Docker image / Build docker image (push) Blocked by required conditions

* Fix Plaid cash balance double counting

* Fix today's cash balance

* Simplify balance trends in activity view
This commit is contained in:
Zach Gollwitzer 2025-05-08 12:25:53 -04:00 committed by GitHub
parent 42207e487e
commit 1e5edd9f2f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 72 additions and 97 deletions

View file

@ -120,4 +120,23 @@ class Balance::ReverseCalculatorTest < ActiveSupport::TestCase
assert_equal expected, calculated
end
test "uses provider reported holdings and cash value on current day" do
aapl = securities(:aapl)
# Implied holdings value of $1,000 from provider
@account.update!(cash_balance: 19000, balance: 20000)
# Create a holding that differs in value from provider ($2,000 vs. the $1,000 reported by provider)
Holding.create!(date: Date.current, account: @account, security: aapl, qty: 10, price: 100, amount: 2000, currency: "USD")
Holding.create!(date: 1.day.ago.to_date, account: @account, security: aapl, qty: 10, price: 100, amount: 2000, currency: "USD")
# Today reports the provider value. Yesterday, provider won't give us any data, so we MUST look at the generated holdings value
# to calculate the end balance ($19,000 cash + $2,000 holdings = $21,000 total value)
expected = [ 21000, 20000 ]
calculated = Balance::ReverseCalculator.new(@account).calculate.sort_by(&:date).map(&:balance)
assert_equal expected, calculated
end
end