The personal finance app for everyone (by everyone)
Ruby
Centralize `investment_contributions` category handling using i18n key and streamline related references.
luckyPipewrench480e53710a01
diff --git a/app/models/account/provider_import_adapter.rb b/app/models/account/provider_import_adapter.rbindex 28bf61cf90..8232e2a1e2 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::DEFAULT_INVESTMENT_CONTRIBUTIONS_NAME)+ auto_category = account.family.categories.find_by(name: Category.investment_contributions_name)end# Set investment activity label, kind, and category if detecteddiff --git a/app/models/category.rb b/app/models/category.rbindex 3dfb8a8093..9a83488fc4 100644--- a/app/models/category.rb+++ b/app/models/category.rb@@ -35,13 +35,10 @@ class Category < ApplicationRecordPAYMENT_COLOR = "#db5a54"TRADE_COLOR = "#e99537"- # Synthetic category name keys for i18n+ # Category name keys for i18nUNCATEGORIZED_NAME_KEY = "models.category.uncategorized"OTHER_INVESTMENTS_NAME_KEY = "models.category.other_investments"-- # Default category name for investment contributions (bootstrapped category)- # This is the canonical English name used when seeding categories via bootstrap!- DEFAULT_INVESTMENT_CONTRIBUTIONS_NAME = "Investment Contributions"+ INVESTMENT_CONTRIBUTIONS_NAME_KEY = "models.category.investment_contributions"class Groupattr_reader :category, :subcategories@@ -117,6 +114,11 @@ class Category < ApplicationRecordI18n.t(OTHER_INVESTMENTS_NAME_KEY)end+ # Helper to get the localized name for investment contributions+ def investment_contributions_name+ I18n.t(INVESTMENT_CONTRIBUTIONS_NAME_KEY)+ end+privatedef default_categories[@@ -141,7 +143,7 @@ class Category < ApplicationRecord[ "Services", "#7c3aed", "briefcase", "expense" ],[ "Fees", "#6b7280", "receipt", "expense" ],[ "Savings & Investments", "#059669", "piggy-bank", "expense" ],- [ "Investment Contributions", "#0d9488", "trending-up", "expense" ]+ [ investment_contributions_name, "#0d9488", "trending-up", "expense" ]]endenddiff --git a/app/models/transfer/creator.rb b/app/models/transfer/creator.rbindex 70b143b24b..0ac93d8f35 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::DEFAULT_INVESTMENT_CONTRIBUTIONS_NAME)+ source_account.family.categories.find_by(name: Category.investment_contributions_name)enddef inflow_transactiondiff --git a/config/locales/models/category/ca.yml b/config/locales/models/category/ca.ymlindex 6d1980a6cf..3102935773 100644--- a/config/locales/models/category/ca.yml+++ b/config/locales/models/category/ca.yml@@ -4,3 +4,4 @@ ca:category:other_investments: Altres inversionsuncategorized: Sense categoria+ investment_contributions: Contribucions d'inversiódiff --git a/config/locales/models/category/en.yml b/config/locales/models/category/en.ymlindex dc86eba560..749f808600 100644--- a/config/locales/models/category/en.yml+++ b/config/locales/models/category/en.yml@@ -4,3 +4,4 @@ en:category:uncategorized: Uncategorizedother_investments: Other Investments+ investment_contributions: Investment Contributionsdiff --git a/config/locales/models/category/fr.yml b/config/locales/models/category/fr.ymlindex 2c9a907a26..eef81bda0f 100644--- a/config/locales/models/category/fr.yml+++ b/config/locales/models/category/fr.yml@@ -4,3 +4,4 @@ fr:category:uncategorized: Non catégoriséother_investments: Autres investissements+ investment_contributions: Contributions aux investissementsdiff --git a/config/locales/models/category/nl.yml b/config/locales/models/category/nl.ymlindex 9428ab9cf4..63edada657 100644--- a/config/locales/models/category/nl.yml+++ b/config/locales/models/category/nl.yml@@ -4,3 +4,4 @@ nl:category:uncategorized: Ongecategoriseerdother_investments: Overige beleggingen+ investment_contributions: Investeringsbijdragendiff --git a/test/test_helper.rb b/test/test_helper.rbindex b44fcdeb33..867f198332 100644--- a/test/test_helper.rb+++ b/test/test_helper.rb@@ -82,7 +82,7 @@ module ActiveSupport# Ensures the Investment Contributions category exists for a family# Used in transfer tests where this bootstrapped category is requireddef ensure_investment_contributions_category(family)- family.categories.find_or_create_by!(name: Category::DEFAULT_INVESTMENT_CONTRIBUTIONS_NAME) do |c|+ family.categories.find_or_create_by!(name: Category.investment_contributions_name) do |c|c.color = "#0d9488"c.lucide_icon = "trending-up"c.classification = "expense"