From a75cb816c7dad6d41e7ea438bbdae9f7787ace52 Mon Sep 17 00:00:00 2001 From: luckyPipewrench Date: Tue, 20 Jan 2026 17:51:36 -0500 Subject: [PATCH] Centralize `investment_contributions_category` logic and update references for streamlined handling. --- app/models/account/provider_import_adapter.rb | 2 +- app/models/family.rb | 6 ++++++ app/models/transfer/creator.rb | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/account/provider_import_adapter.rb b/app/models/account/provider_import_adapter.rb index 8232e2a1e..64ba64c81 100644 --- a/app/models/account/provider_import_adapter.rb +++ b/app/models/account/provider_import_adapter.rb @@ -155,7 +155,7 @@ class Account::ProviderImportAdapter auto_kind = "funds_movement" elsif detected_label == "Contribution" auto_kind = "investment_contribution" - auto_category = account.family.categories.find_by(name: Category.investment_contributions_name) + auto_category = account.family.investment_contributions_category end # Set investment activity label, kind, and category if detected diff --git a/app/models/family.rb b/app/models/family.rb index 8e48ced1c..ac3d3da41 100644 --- a/app/models/family.rb +++ b/app/models/family.rb @@ -79,6 +79,12 @@ class Family < ApplicationRecord @income_statement ||= IncomeStatement.new(self) end + # Returns the Investment Contributions category for this family, or nil if not found. + # This is a bootstrapped category used for auto-categorizing transfers to investment accounts. + def investment_contributions_category + categories.find_by(name: Category.investment_contributions_name) + end + def investment_statement @investment_statement ||= InvestmentStatement.new(self) end diff --git a/app/models/transfer/creator.rb b/app/models/transfer/creator.rb index 0ac93d8f3..1825e92d0 100644 --- a/app/models/transfer/creator.rb +++ b/app/models/transfer/creator.rb @@ -43,7 +43,7 @@ class Transfer::Creator end def investment_contributions_category - source_account.family.categories.find_by(name: Category.investment_contributions_name) + source_account.family.investment_contributions_category end def inflow_transaction