module Mks module Edm class EquipmentValuation < ApplicationRecord include Mks::Edm::Defaults before_save :reset_current, if: :current? belongs_to :equipment_item validates :initial_cost, :residual_value, :work_hrs_per_yr, :life_year, :insurance_premium, :fuel_cost_per_hr, presence: true default :is_current, true def reset_current valuations = EquipmentValuation.where(is_current: true, equipment_item: equipment_item) valuations.each { |valuation| valuation.is_current = false } valuations.each(&:save!) end def current? is_current end end end end