refactor(holdings): move PortfolioCache FX fix to dedicated branch

Remove date-accurate exchange rate fix from this branch — it has been
split into fix/portfolio-cache-historical-fx-rate to keep concerns
separate.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
CrossDrain
2026-05-18 13:17:13 +03:00
parent 694463dd5d
commit 36676784c5
2 changed files with 1 additions and 37 deletions

View File

@@ -40,7 +40,7 @@ class Holding::PortfolioCache
price_money = Money.new(price.price, price.currency)
begin
converted_amount = price_money.exchange_to(account.currency, date: date).amount
converted_amount = price_money.exchange_to(account.currency).amount
rescue Money::ConversionError
converted_amount = price.price
end

View File

@@ -56,40 +56,4 @@ class Holding::PortfolioCacheTest < ActiveSupport::TestCase
cache = Holding::PortfolioCache.new(@account, use_holdings: true)
assert_equal holding.price, cache.get_price(@security.id, holding.date).price
end
test "converts historical prices using the requested date exchange rate" do
account = families(:empty).accounts.create!(
name: "CHF Brokerage",
balance: 10000,
currency: "CHF",
accountable: Investment.new
)
holding_date = 2.days.ago.to_date
ExchangeRate.create!(from_currency: "USD", to_currency: "CHF", date: holding_date, rate: 0.80)
ExchangeRate.create!(from_currency: "USD", to_currency: "CHF", date: Date.current, rate: 0.95)
Holding.create!(
security: @security,
account: account,
date: holding_date,
qty: 1,
price: 100,
amount: 100,
currency: "USD"
)
Security::Price.create!(
security: @security,
date: holding_date,
price: 100,
currency: "USD"
)
cache = Holding::PortfolioCache.new(account, use_holdings: true)
converted_price = cache.get_price(@security.id, holding_date)
assert_equal BigDecimal("80.0"), converted_price.price
assert_equal "CHF", converted_price.currency
end
end