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

@@ -0,0 +1,13 @@
class AddInvestmentCashflowSupport < ActiveRecord::Migration[7.2]
def change
# Flag for excluding from cashflow (user-controllable)
# Used for internal investment activity like fund swaps
add_column :entries, :exclude_from_cashflow, :boolean, default: false, null: false
add_index :entries, :exclude_from_cashflow
# Holdings snapshot for comparison (provider-agnostic)
# Used to detect internal investment activity by comparing holdings between syncs
add_column :accounts, :holdings_snapshot_data, :jsonb
add_column :accounts, :holdings_snapshot_at, :datetime
end
end

View File

@@ -0,0 +1,8 @@
class AddInvestmentActivityLabelToTransactions < ActiveRecord::Migration[7.2]
def change
# Label for investment activity type (Buy, Sell, Sweep In, Dividend, etc.)
# Provides human-readable context for why a transaction is excluded from cashflow
add_column :transactions, :investment_activity_label, :string
add_index :transactions, :investment_activity_label
end
end