The personal finance app for everyone (by everyone)
Ruby
Localize investment activity labels and improve transaction processing
Josh Waldrep307a8bb76045
diff --git a/app/models/account/provider_import_adapter.rb b/app/models/account/provider_import_adapter.rbindex 31d65a6ae6..dac0da8d44 100644--- a/app/models/account/provider_import_adapter.rb+++ b/app/models/account/provider_import_adapter.rb@@ -119,11 +119,12 @@ class Account::ProviderImportAdapter# Set investment activity label if provided and not already setif investment_activity_label.present? && entry.entryable.is_a?(Transaction)if entry.transaction.investment_activity_label.blank?- entry.transaction.update!(investment_activity_label: investment_activity_label)+ entry.transaction.assign_attributes(investment_activity_label: investment_activity_label)endendentry.save!+ entry.transaction.save! if entry.transaction.changed?# AFTER save: For NEW posted transactions, check for fuzzy matches to SUGGEST (not auto-claim)# This handles tip adjustments where auto-matching is too riskydiff --git a/app/models/investment_activity_detector.rb b/app/models/investment_activity_detector.rbindex c030d9cdf9..2ef6c2f714 100644--- a/app/models/investment_activity_detector.rb+++ b/app/models/investment_activity_detector.rb@@ -119,8 +119,9 @@ class InvestmentActivityDetectorend# Check for dividend patterns- if description == "CASH" || description.include?("DIVIDEND") ||- description.include?("DISTRIBUTION")+ # "CASH" alone typically indicates dividend payout in brokerage feeds (only for inflows)+ if description.include?("DIVIDEND") || description.include?("DISTRIBUTION") ||+ (description == "CASH" && amount < 0)return "Dividend"enddiff --git a/app/views/transactions/_transaction.html.erb b/app/views/transactions/_transaction.html.erbindex a4593a56d3..c645d515de 100644--- a/app/views/transactions/_transaction.html.erb+++ b/app/views/transactions/_transaction.html.erb@@ -87,7 +87,7 @@<%# Investment activity label badge %><% if transaction.investment_activity_label.present? %><span class="inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium bg-alpha-black-50 text-secondary" title="<%= t("transactions.transaction.activity_type_tooltip") %>">- <%= transaction.investment_activity_label %>+ <%= t("transactions.activity_labels.#{transaction.investment_activity_label.parameterize(separator: '_')}") %></span><% end %>diff --git a/app/views/transactions/show.html.erb b/app/views/transactions/show.html.erbindex 85e7705095..4af991f1a5 100644--- a/app/views/transactions/show.html.erb+++ b/app/views/transactions/show.html.erb@@ -240,7 +240,7 @@<%= ef.select :investment_activity_label,options_for_select(- [["—", nil]] + Transaction::ACTIVITY_LABELS.map { |l| [l, l] },+ [["—", nil]] + Transaction::ACTIVITY_LABELS.map { |l| [t("transactions.activity_labels.#{l.parameterize(separator: '_')}"), l] },@entry.entryable.investment_activity_label),{ label: false },@@ -260,8 +260,8 @@<%= f.fields_for :entryable do |ef| %><div class="flex cursor-pointer items-center gap-4 justify-between"><div class="text-sm space-y-1">- <h4 class="text-primary">One-time <%= @entry.amount.negative? ? "Income" : "Expense" %></h4>- <p class="text-secondary">One-time transactions will be excluded from certain budgeting calculations and reports to help you see what's really important.</p>+ <h4 class="text-primary"><%= t(".one_time_title", type: @entry.amount.negative? ? t("transactions.form.income") : t("transactions.form.expense")) %></h4>+ <p class="text-secondary"><%= t(".one_time_description") %></p></div><%= ef.toggle :kind, {diff --git a/config/locales/views/transactions/en.yml b/config/locales/views/transactions/en.ymlindex 0a393d835f..267adce436 100644--- a/config/locales/views/transactions/en.yml+++ b/config/locales/views/transactions/en.yml@@ -38,6 +38,22 @@ en:exclude_from_cashflow_description_investment: Hide from income/expense reports and Sankey chart. Use for internal investment activity like fund swaps, reinvestments, or money market sweeps.activity_type: Activity Typeactivity_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.+ activity_labels:+ buy: Buy+ sell: Sell+ sweep_in: Sweep In+ sweep_out: Sweep Out+ dividend: Dividend+ reinvestment: Reinvestment+ interest: Interest+ fee: Fee+ transfer: Transfer+ contribution: Contribution+ withdrawal: Withdrawal+ exchange: Exchange+ other: Othermark_recurring: Mark as Recurringmark_recurring_subtitle: Track this as a recurring transaction. Amount variance is automatically calculated from past 6 months of similar transactions.mark_recurring_title: Recurring Transactiondiff --git a/lib/tasks/investment_labels.rake b/lib/tasks/investment_labels.rakeindex 31741574ad..9cefae7c93 100644--- a/lib/tasks/investment_labels.rake+++ b/lib/tasks/investment_labels.rake@@ -78,6 +78,7 @@ namespace :sure do# Find transactions (optionally include already-labeled if force=true)entries = account.entries.joins("INNER JOIN transactions ON transactions.id = entries.entryable_id AND entries.entryable_type = 'Transaction'")+ .includes(:entryable)unless forceentries = entries.where("transactions.investment_activity_label IS NULL OR transactions.investment_activity_label = ''")@@ -160,8 +161,11 @@ namespace :sure dotrueelsif %w[1 true yes y].include?(dry_raw)true- else+ elsif %w[0 false no n].include?(dry_raw)false+ else+ puts({ ok: false, error: "invalid_argument", message: "dry_run must be one of: true/yes/1 or false/no/0" }.to_json)+ exit 1endaccount = Account.find(account_id)