Add investment activity detection, labels, and exclusions

- Introduced `InvestmentActivityDetector` to mark internal investment activity as excluded from cashflow and assign appropriate labels.
- Added `exclude_from_cashflow` flag to `entries` and `investment_activity_label` to `transactions` with migrations.
- Implemented rake tasks to backfill and clear investment activity labels.
- Updated `PlaidAccount::Investments::TransactionsProcessor` to map Plaid transaction types to labels.
- Included comprehensive test coverage for new functionality.
This commit is contained in:
Josh Waldrep
2026-01-10 19:48:04 -05:00
parent 70e7a5f2d6
commit 52588784d0
26 changed files with 1235 additions and 82 deletions

View File

@@ -18,4 +18,37 @@ class TransactionTest < ActiveSupport::TestCase
assert_not transaction.pending?
end
test "investment_contribution is a valid kind" do
transaction = Transaction.new(kind: "investment_contribution")
assert_equal "investment_contribution", transaction.kind
assert transaction.investment_contribution?
end
test "all transaction kinds are valid" do
valid_kinds = %w[standard funds_movement cc_payment loan_payment one_time investment_contribution]
valid_kinds.each do |kind|
transaction = Transaction.new(kind: kind)
assert_equal kind, transaction.kind, "#{kind} should be a valid transaction kind"
end
end
test "INTERNAL_ACTIVITY_LABELS contains expected labels" do
assert_includes Transaction::INTERNAL_ACTIVITY_LABELS, "Buy"
assert_includes Transaction::INTERNAL_ACTIVITY_LABELS, "Sell"
assert_includes Transaction::INTERNAL_ACTIVITY_LABELS, "Reinvestment"
assert_includes Transaction::INTERNAL_ACTIVITY_LABELS, "Exchange"
end
test "ACTIVITY_LABELS contains all valid labels" do
assert_includes Transaction::ACTIVITY_LABELS, "Buy"
assert_includes Transaction::ACTIVITY_LABELS, "Sell"
assert_includes Transaction::ACTIVITY_LABELS, "Sweep In"
assert_includes Transaction::ACTIVITY_LABELS, "Sweep Out"
assert_includes Transaction::ACTIVITY_LABELS, "Dividend"
assert_includes Transaction::ACTIVITY_LABELS, "Interest"
assert_includes Transaction::ACTIVITY_LABELS, "Fee"
end
end