From 36676784c56f0680221bd54d46bf9fb6949a0cf4 Mon Sep 17 00:00:00 2001 From: CrossDrain <32982516+CrossDrain@users.noreply.github.com> Date: Mon, 18 May 2026 13:17:13 +0300 Subject: [PATCH] refactor(holdings): move PortfolioCache FX fix to dedicated branch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app/models/holding/portfolio_cache.rb | 2 +- test/models/holding/portfolio_cache_test.rb | 36 --------------------- 2 files changed, 1 insertion(+), 37 deletions(-) diff --git a/app/models/holding/portfolio_cache.rb b/app/models/holding/portfolio_cache.rb index 4ea52920e..ca6febe2e 100644 --- a/app/models/holding/portfolio_cache.rb +++ b/app/models/holding/portfolio_cache.rb @@ -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 diff --git a/test/models/holding/portfolio_cache_test.rb b/test/models/holding/portfolio_cache_test.rb index fed652165..4677fc411 100644 --- a/test/models/holding/portfolio_cache_test.rb +++ b/test/models/holding/portfolio_cache_test.rb @@ -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