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