Sha256: 98332983bb77937b66e11d7364fc02ffee88f1a4106263c4907d1a2b1833d348

Contents?: true

Size: 845 Bytes

Versions: 16

Compression:

Stored size: 845 Bytes

Contents

module Ecom
  module Core
    class UnitCost < ApplicationRecord
      before_save :update_previous_unit_cost

      belongs_to :resource_type
      belongs_to :measurement_unit
      belongs_to :currency
      belongs_to :set_by, class_name: 'Ecom::Core::User'

      validates :quantity, :effective_date, :utilization_factor, :set_by_id, :set_by, presence: true

      validates :price, presence: true, numericality: { greater_than: 0 }
      validates :utilization_factor, presence: true, numericality: { greater_than: 0, less_than_or_equal_to: 1 }

      def update_previous_unit_cost
        return if resource_type_id.nil?

        return if active_changed?(from: true, to: false)

        Ecom::Core::UnitCost
          .where(resource_type_id: resource_type_id, active: true)
          .update(active: false)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ecom_core-1.3.14 app/models/ecom/core/unit_cost.rb
ecom_core-1.3.13 app/models/ecom/core/unit_cost.rb
ecom_core-1.3.12 app/models/ecom/core/unit_cost.rb
ecom_core-1.3.11 app/models/ecom/core/unit_cost.rb
ecom_core-1.3.10 app/models/ecom/core/unit_cost.rb
ecom_core-1.3.9 app/models/ecom/core/unit_cost.rb
ecom_core-1.3.8 app/models/ecom/core/unit_cost.rb
ecom_core-1.3.7 app/models/ecom/core/unit_cost.rb
ecom_core-1.3.6 app/models/ecom/core/unit_cost.rb
ecom_core-1.3.5 app/models/ecom/core/unit_cost.rb
ecom_core-1.3.4 app/models/ecom/core/unit_cost.rb
ecom_core-1.3.3 app/models/ecom/core/unit_cost.rb
ecom_core-1.3.2 app/models/ecom/core/unit_cost.rb
ecom_core-1.3.1 app/models/ecom/core/unit_cost.rb
ecom_core-1.3.0 app/models/ecom/core/unit_cost.rb
ecom_core-1.2.36 app/models/ecom/core/unit_cost.rb