The personal finance app for everyone (by everyone)
Ruby
Keep contribution-labelled deposits on bank accounts out of investment contributions (#5735)
lucasudard6e277bb58ab
diff --git a/app/models/account/provider_import_adapter.rb b/app/models/account/provider_import_adapter.rbindex 9d4a02c938..a4d06c5844 100644--- a/app/models/account/provider_import_adapter.rb+++ b/app/models/account/provider_import_adapter.rb@@ -268,7 +268,10 @@ class Account::ProviderImportAdapterauto_category = nilif Transaction::INTERNAL_MOVEMENT_LABELS.include?(detected_label)auto_kind = "funds_movement"- elsif detected_label == "Contribution"+ elsif detected_label == "Contribution" && (account.investment? || account.crypto?)+ # Some providers (SnapTrade for Wealthsimple cash accounts) label every+ # deposit on a bank account CONTRIBUTION. There it is salary or another+ # inflow, not money moving into an investment, so it keeps its own kind.auto_kind = "investment_contribution"auto_category = account.family.investment_contributions_categoryelsif account.accountable_type == "Loan" && entry.amount.negative?diff --git a/test/models/account/provider_import_adapter_test.rb b/test/models/account/provider_import_adapter_test.rbindex f859c64ceb..81b5f399af 100644--- a/test/models/account/provider_import_adapter_test.rb+++ b/test/models/account/provider_import_adapter_test.rb@@ -152,6 +152,21 @@ class Account::ProviderImportAdapterTest < ActiveSupport::TestCaseassert_nil broker_entry.transaction.categoryend+ test "a deposit labelled as a contribution on a bank account stays a standard inflow" do+ entry = @adapter.import_transaction(+ external_id: "snaptrade_chequing_deposit_1",+ amount: -1500.00,+ currency: "USD",+ date: Date.current,+ name: "Payroll deposit",+ source: "snaptrade",+ investment_activity_label: "Contribution"+ )++ assert_equal "standard", entry.transaction.kind+ assert_nil entry.transaction.category+ end+test "re-importing a contribution the user turned into a plain transfer keeps that choice" dochecking_entry = @adapter.import_transaction(external_id: "plaid_checking_to_broker",diff --git a/test/models/trade_republic_account_activities_processor_test.rb b/test/models/trade_republic_account_activities_processor_test.rbindex f59feaf7bb..c8df47f8c2 100644--- a/test/models/trade_republic_account_activities_processor_test.rb+++ b/test/models/trade_republic_account_activities_processor_test.rb@@ -1496,6 +1496,8 @@ class TradeRepublicAccountActivitiesProcessorTest < ActiveSupport::TestCasedate: Date.parse("2026-08-01"),name: "Cash in",source: "trade_republic",+ kind: "investment_contribution",+ category_id: category.id,investment_activity_label: "Contribution")assert_equal "investment_contribution", legacy.transaction.kind