Skip to content

armgit / sure

Public Imported from GitHub
0

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.rb
index 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::ProviderImportAdapter
auto_category = nil
if 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_category
elsif 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.rb
index 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::TestCase
assert_nil broker_entry.transaction.category
end
+ 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" do
checking_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.rb
index 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::TestCase
date: 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