Files
sure/app/controllers/retirement_controller.rb
ChakibMoMi d57bdd02e1 Polish retirement feature: Custom calculator, grouped select, auto-detect, UK progress
- Extract Custom pension calculator class (was mapped to Base, which raises
  NotImplementedError — now explicit and safe)
- Remove if/custom short-circuit from estimated_monthly_pension — all systems
  go through pension_calculator uniformly
- Add PENSION_SYSTEM_GROUPS constant for grouped UI select and
  COUNTRY_TO_PENSION_SYSTEM + suggest_pension_system(country) for auto-detection
- Setup action pre-selects pension system and country from family profile
- Form dropdown now uses grouped_options_for_select grouped by region
- Show page displays UK State Pension qualifying-years progress bar for uk_sp
- Add pension_system_groups i18n keys in EN/DE/ES/FR
- Add UK progress i18n keys (uk_progress_title, uk_qualifying_years,
  uk_years_remaining) in all four locales
- Add 5 calculator unit tests (DE, US, UK, FR, ES) and update schema.rb
  to reflect GeneralizePensionSystems migration (pension_params JSONB,
  data JSONB, current_points nullable, old DE-specific columns removed)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-24 03:41:18 +02:00

97 lines
2.7 KiB
Ruby

class RetirementController < ApplicationController
before_action :set_retirement_config, only: %i[show edit update]
before_action :require_retirement_config, only: %i[add_pension_entry destroy_pension_entry]
def show
@pension_entries = @retirement_config.pension_entries_with_gains
end
def setup
@retirement_config = Current.family.retirement_config || Current.family.build_retirement_config(
birth_year: 1990,
currency: Current.family.currency,
country: Current.family.country,
pension_system: RetirementConfig.suggest_pension_system(Current.family.country)
)
end
def create
# Guard against duplicate creation (unique index on family_id)
if Current.family.retirement_config
redirect_to retirement_path
return
end
@retirement_config = Current.family.build_retirement_config(retirement_config_params)
if @retirement_config.save
redirect_to retirement_path, notice: t(".created")
else
render :setup, status: :unprocessable_entity
end
end
def edit
end
def update
if @retirement_config.update(retirement_config_params)
redirect_to retirement_path, notice: t(".updated")
else
render :edit, status: :unprocessable_entity
end
end
def add_pension_entry
@pension_entry = @retirement_config.pension_entries.build(pension_entry_params)
if @pension_entry.save
redirect_to retirement_path, notice: t(".pension_entry_added")
else
@pension_entries = @retirement_config.pension_entries_with_gains
render :show, status: :unprocessable_entity
end
end
def destroy_pension_entry
@pension_entry = @retirement_config.pension_entries.find(params[:id])
@pension_entry.destroy!
redirect_to retirement_path, notice: t(".pension_entry_removed")
end
private
def set_retirement_config
@retirement_config = Current.family.retirement_config
unless @retirement_config
redirect_to setup_retirement_path
end
end
def require_retirement_config
@retirement_config = Current.family.retirement_config
unless @retirement_config
redirect_to setup_retirement_path, alert: t("retirement.show.setup_required")
end
end
def retirement_config_params
params.require(:retirement_config).permit(
:country, :pension_system, :birth_year, :retirement_age,
:target_monthly_income, :currency, :expected_return_pct,
:inflation_pct, :tax_rate_pct, :current_monthly_savings,
pension_params: {}
)
end
def pension_entry_params
params.require(:pension_entry).permit(
:recorded_at, :current_points, :current_monthly_pension,
:projected_monthly_pension, :notes,
data: {}
)
end
end