mirror of
https://github.com/we-promise/sure.git
synced 2026-05-28 15:04:57 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user