The personal finance app for everyone (by everyone)
Ruby
Fix E*Trade cost_basis stored as per-share when total (#3619)
Alan Tsed3f2c9328af8
diff --git a/app/models/simplefin_account/investments/holdings_processor.rb b/app/models/simplefin_account/investments/holdings_processor.rbindex 888822b141..4769934de1 100644--- a/app/models/simplefin_account/investments/holdings_processor.rb+++ b/app/models/simplefin_account/investments/holdings_processor.rb@@ -224,7 +224,7 @@ class SimplefinAccount::Investments::HoldingsProcessor# field with the total position cost rather than the per-share value the# spec requires. Matched as case-insensitive substrings against the# account's stored org name and domain.- TOTAL_BASIS_INSTITUTIONS = %w[vanguard fidelity schwab].freeze+ TOTAL_BASIS_INSTITUTIONS = %w[vanguard fidelity schwab etrade e*trade].freezedef institution_reports_total_basis?org = simplefin_account.respond_to?(:org_data) ? simplefin_account.org_data : nildiff --git a/test/models/simplefin_account/investments/holdings_processor_test.rb b/test/models/simplefin_account/investments/holdings_processor_test.rbindex 852d4daa0b..395e4ff203 100644--- a/test/models/simplefin_account/investments/holdings_processor_test.rb+++ b/test/models/simplefin_account/investments/holdings_processor_test.rb@@ -122,7 +122,7 @@ class SimplefinAccount::Investments::HoldingsProcessorTest < ActiveSupport::Testassert_equal BigDecimal("100.00"), cost_basisend- test "institution_reports_total_basis? matches Vanguard, Fidelity, and Schwab org metadata" do+ test "institution_reports_total_basis? matches Vanguard, Fidelity, Schwab, and E*Trade org metadata" docases = {{ "name" => "Vanguard" } => true,{ "name" => "VANGUARD BROKERAGE" } => true,@@ -130,6 +130,8 @@ class SimplefinAccount::Investments::HoldingsProcessorTest < ActiveSupport::Test{ "domain" => "vanguard.com" } => true,{ "domain" => "401k.fidelity.com" } => true,{ "name" => "Charles Schwab", "domain" => "schwab.com" } => true,+ { "name" => "E*Trade" } => true,+ { "domain" => "us.etrade.com" } => true,{ "name" => "Chase" } => false,{} => false}@@ -165,6 +167,20 @@ class SimplefinAccount::Investments::HoldingsProcessorTest < ActiveSupport::Testassert_in_delta 46.33, cost_basis.to_f, 0.01end+ test "cost_basis from E*Trade is divided by qty (#3618)" do+ # Same failure mode as Vanguard/Fidelity (#1718) and Schwab (#2626):+ # E*Trade's cost_basis is total position cost, not per-share.+ cost_basis = @processor.send(+ :normalize_cost_basis,+ BigDecimal("3850.00"),+ BigDecimal("100"),+ "cost_basis",+ true # institution_reports_total_basis?+ )++ assert_in_delta 38.50, cost_basis.to_f, 0.01+ end+test "missing cost basis fields return nil" dopayload = {"market_value" => "10108.16"