Sha256: e762c7bf2d184c4da09a28acd12ba763592c6679a6c027cc27065ec52f5ffe67

Contents?: true

Size: 670 Bytes

Versions: 4

Compression:

Stored size: 670 Bytes

Contents

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mks_edm-1.0.5 app/models/mks/edm/equipment_valuation.rb
mks_edm-1.0.4 app/models/mks/edm/equipment_valuation.rb
mks_edm-1.0.2 app/models/mks/edm/equipment_valuation.rb
mks_edm-1.0.1 app/models/mks/edm/equipment_valuation.rb