Improve investment activity labels UX and add convert-to-trade feature (#649)

* Add `investment_activity_label` to trades and enhance activity label handling

- Introduced `investment_activity_label` column to the `trades` table with a migration.
- Backfilled existing `trades` with activity labels based on quantity (`Buy`, `Sell`, or `Other`).
- Replaced `category_id` in trades with `investment_activity_label` for better alignment with transaction labels.
- Updated views and controllers to display and manage activity labels for trades.
- Added localized badge components for displaying and editing labels dynamically.
- Enhanced `PlaidAccount::Investments::TransactionsProcessor` to assign and process activity labels automatically.
- Added investment flows section to reports for tracking contributions and withdrawals.
- Refactored related tests and models for consistency and to ensure proper validation and filtering.

* Improve handling of `investment_activity_label`, trade type, and security selection in trades and transactions

- Refined label assignment logic in `trades_controller` to default to `Buy`/`Sell` based on transaction nature.
- Simplified security selection in `transactions_controller` by resolving via unique IDs or custom tickers.
- Streamlined UI for trade and transaction forms by updating dropdown options and label text.
- Enabled quick-edit badges to open `convert_to_trade` modal when applicable, enhancing flexibility.
- Adjusted tests and views to align with updated workflows and ensure consistent behavior.

* Improve handling of `investment_activity_label`, trade type, and security selection in trades and transactions

- Refined label assignment logic in `trades_controller` to default to `Buy`/`Sell` based on transaction nature.
- Simplified security selection in `transactions_controller` by resolving via unique IDs or custom tickers.
- Streamlined UI for trade and transaction forms by updating dropdown options and label text.
- Enabled quick-edit badges to open `convert_to_trade` modal when applicable, enhancing flexibility.
- Adjusted tests and views to align with updated workflows and ensure consistent behavior.

* Improve handling of `investment_activity_label`, trade type, and security selection in trades and transactions

- Refined label assignment logic in `trades_controller` to default to `Buy`/`Sell` based on transaction nature.
- Simplified security selection in `transactions_controller` by resolving via unique IDs or custom tickers.
- Streamlined UI for trade and transaction forms by updating dropdown options and label text.
- Enabled quick-edit badges to open `convert_to_trade` modal when applicable, enhancing flexibility.
- Adjusted tests and views to align with updated workflows and ensure consistent behavior.

* Add safeguard for `dropdownTarget` existence in quick edit controller

- Prevent errors by ensuring `dropdownTarget` is present before toggling its visibility.

* Fix undefined method 'category' for Trade on mobile view

Trade model uses investment_activity_label, not category. The upstream
merge introduced a call to trade.category which doesn't exist. Use the
activity label badge on mobile instead.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix activity label logic for zero/blank quantity and sell inference

- Return `nil` for blank or zero quantity in `investment_activity_label_for`.
- Correct `is_sell` logic to use the amount’s sign properly in `transactions_controller`.

* Fix i18n key paths in transactions controller for convert_to_trade

- Update flash message translations to use full i18n paths.
- Use `BigDecimal` for quantity and price calculations to improve precision.

---------

Co-authored-by: Josh Waldrep <joshua.waldrep5+github@gmail.com>
Co-authored-by: luckyPipewrench <luckypipewrench@proton.me>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
LPW
2026-01-16 15:04:10 -05:00
committed by GitHub
parent 1ca84d8048
commit 0c2026680c
36 changed files with 885 additions and 154 deletions

View File

@@ -134,6 +134,12 @@ en:
value: Value
return: Return
accounts: Investment Accounts
investment_flows:
title: Investment Flows
description: Track money flowing into and out of your investment accounts
contributions: Contributions
withdrawals: Withdrawals
net_flow: Net Flow
google_sheets_instructions:
title_with_key: "✅ Copy URL for Google Sheets"
title_no_key: "⚠️ API Key Required"

View File

@@ -37,6 +37,9 @@ en:
activity_type_description: Type of investment activity (Buy, Sell, Dividend, etc.). Auto-detected or set manually.
one_time_title: One-time %{type}
one_time_description: One-time transactions will be excluded from certain budgeting calculations and reports to help you see what's really important.
convert_to_trade_title: Convert to Security Trade
convert_to_trade_description: Convert this transaction into a Buy or Sell trade with security details for portfolio tracking.
convert_to_trade_button: Convert to Trade
activity_labels:
buy: Buy
sell: Sell
@@ -103,6 +106,43 @@ en:
category: Category
tag: Tag
merchant: Merchant
convert_to_trade:
title: Convert to Security Trade
description: Convert this transaction into a trade with security details
date_label: "Date:"
account_label: "Account:"
amount_label: "Amount:"
security_label: Security
security_prompt: Select a security...
security_custom: "+ Enter custom ticker"
security_hint: Select from your holdings or enter a custom ticker
ticker_placeholder: AAPL
ticker_hint: Enter the stock/ETF ticker symbol
quantity_label: Quantity (Shares)
quantity_placeholder: e.g. 20
quantity_hint: Number of shares traded
price_label: Price per Share
price_placeholder: e.g. 52.15
price_hint: Price per share (%{currency})
qty_or_price_hint: Enter at least qty OR price. The other will be calculated from the transaction amount (%{amount}).
trade_type_label: Trade Type
trade_type_hint: Buy or Sell shares of a security
exchange_label: Exchange (Optional)
exchange_placeholder: XNAS
exchange_hint: Leave blank to auto-detect
cancel: Cancel
submit: Convert to Trade
success: Transaction converted to trade
errors:
not_investment_account: Only transactions in investment accounts can be converted to trades
already_converted: This transaction has already been converted or excluded
enter_ticker: Please enter a ticker symbol
security_not_found: Selected security no longer exists. Please select another.
select_security: Please select or enter a security
enter_qty_or_price: Please enter either quantity or price per share. The other will be calculated from the transaction amount.
invalid_qty_or_price: Invalid quantity or price. Please enter valid positive values.
conversion_failed: "Failed to convert transaction: %{error}"
unexpected_error: "Unexpected error during conversion: %{error}"
searches:
filters:
amount_filter:

View File

@@ -197,6 +197,8 @@ Rails.application.routes.draw do
end
member do
get :convert_to_trade
post :create_trade_from_transaction
post :mark_as_recurring
post :merge_duplicate
post :dismiss_duplicate