Files
sure/app/models/pension_entry.rb
ChakibMoMi 4f3230c904 Generalize pension system: multi-country strategy pattern
- Add JSONB pension_params column to retirement_configs
- Add data JSONB column to pension_entries
- Create pension calculator strategy classes (Base, DeGrv, UsSocialSecurity, UkStatePension, FrRegimeGeneral, EsSocialSecurity)
- Update RetirementConfig model to delegate to calculators
- Make PensionEntry.current_points optional for non-points systems
- Update controller strong params (pension_params: {})
- Add Stimulus pension_system_controller for dynamic form fields
- Update views with per-country field groups and conditional points columns
- Expand i18n (EN, DE) and add ES, FR locale files
- Update fixtures and tests for new schema

Addresses review feedback from jjmata on PR #1057
2026-04-09 00:37:11 +02:00

24 lines
890 B
Ruby

class PensionEntry < ApplicationRecord
belongs_to :retirement_config
validates :recorded_at, presence: true, uniqueness: { scope: :retirement_config_id }
validates :current_points, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
validates :current_monthly_pension, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
validates :projected_monthly_pension, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
scope :chronological, -> { order(recorded_at: :asc) }
scope :reverse_chronological, -> { order(recorded_at: :desc) }
def points_gained
return nil unless current_points
previous = retirement_config.pension_entries
.where("recorded_at < ?", recorded_at)
.order(recorded_at: :desc)
.first
return current_points unless previous&.current_points
current_points - previous.current_points
end
end