1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-05 05:25:24 +02:00

Fix EU plaid flow (#1761)

* Fix EU plaid flow

* Fix failing tests
This commit is contained in:
Zach Gollwitzer 2025-01-31 17:04:26 -05:00 committed by GitHub
parent 4bf72506d5
commit 53f4b32c33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 91 additions and 86 deletions

View file

@ -11,7 +11,7 @@ class Account::BalanceCalculator
holdings_value = converted_holdings.select { |h| h.date == balance.date }.sum(&:amount)
balance.balance = balance.balance + holdings_value
balance
end
end.compact
end
private

View file

@ -76,29 +76,33 @@ class Account::Syncer
exchange_rates = ExchangeRate.find_rates(
from: from_currency,
to: to_currency,
start_date: balances.first.date
start_date: balances.min_by(&:date).date
)
converted_balances = balances.map do |balance|
exchange_rate = exchange_rates.find { |er| er.date == balance.date }
next unless exchange_rate.present?
account.balances.build(
date: balance.date,
balance: exchange_rate.rate * balance.balance,
currency: to_currency
) if exchange_rate.present?
end
)
end.compact
converted_holdings = holdings.map do |holding|
exchange_rate = exchange_rates.find { |er| er.date == holding.date }
next unless exchange_rate.present?
account.holdings.build(
security: holding.security,
date: holding.date,
amount: exchange_rate.rate * holding.amount,
currency: to_currency
) if exchange_rate.present?
end
)
end.compact
Account.transaction do
load_balances(converted_balances)