The personal finance app for everyone (by everyone)
Ruby
Centralize `investment_contributions_category` logic and update references for streamlined handling.
luckyPipewrencha75cb816c7da
diff --git a/app/models/account/provider_import_adapter.rb b/app/models/account/provider_import_adapter.rbindex 8232e2a1e2..64ba64c811 100644--- a/app/models/account/provider_import_adapter.rb+++ b/app/models/account/provider_import_adapter.rb@@ -155,7 +155,7 @@ class Account::ProviderImportAdapterauto_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_categoryend# Set investment activity label, kind, and category if detecteddiff --git a/app/models/family.rb b/app/models/family.rbindex 8e48ced1c7..ac3d3da410 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)enddiff --git a/app/models/transfer/creator.rb b/app/models/transfer/creator.rbindex 0ac93d8f35..1825e92d02 100644--- a/app/models/transfer/creator.rb+++ b/app/models/transfer/creator.rb@@ -43,7 +43,7 @@ class Transfer::Creatorenddef investment_contributions_category- source_account.family.categories.find_by(name: Category.investment_contributions_name)+ source_account.family.investment_contributions_categoryenddef inflow_transaction