Centralize investment_contributions category handling using i18n key and streamline related references.

This commit is contained in:
luckyPipewrench
2026-01-20 17:36:56 -05:00
parent 4727a391a7
commit 480e53710a
8 changed files with 15 additions and 9 deletions

View File

@@ -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::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 detected

View File

@@ -35,13 +35,10 @@ class Category < ApplicationRecord
PAYMENT_COLOR = "#db5a54"
TRADE_COLOR = "#e99537"
# Synthetic category name keys for i18n
# Category name keys for i18n
UNCATEGORIZED_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 Group
attr_reader :category, :subcategories
@@ -117,6 +114,11 @@ class Category < ApplicationRecord
I18n.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
private
def 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" ]
]
end
end

View File

@@ -43,7 +43,7 @@ class Transfer::Creator
end
def 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)
end
def inflow_transaction

View File

@@ -4,3 +4,4 @@ ca:
category:
other_investments: Altres inversions
uncategorized: Sense categoria
investment_contributions: Contribucions d'inversió

View File

@@ -4,3 +4,4 @@ en:
category:
uncategorized: Uncategorized
other_investments: Other Investments
investment_contributions: Investment Contributions

View File

@@ -4,3 +4,4 @@ fr:
category:
uncategorized: Non catégorisé
other_investments: Autres investissements
investment_contributions: Contributions aux investissements

View File

@@ -4,3 +4,4 @@ nl:
category:
uncategorized: Ongecategoriseerd
other_investments: Overige beleggingen
investment_contributions: Investeringsbijdragen

View File

@@ -82,7 +82,7 @@ module ActiveSupport
# Ensures the Investment Contributions category exists for a family
# Used in transfer tests where this bootstrapped category is required
def 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"