module Mks module Edm class EquipmentItem < ApplicationRecord READY = 'Ready' UNDER_MAINTENANCE = 'Under Maintenance' belongs_to :equipment belongs_to :current_location, class_name: 'Mks::Edm::EquipmentLocation', optional: true validates :code, :name, :serial_number, :purchase_price, :purchase_date, presence: true validates :code, :serial_number, uniqueness: true # validates :status, inclusion: { in: %w[READY UNDER_MAINTENANCE] }, allow_nil: true delegate(:name, to: :equipment, prefix: true) after_initialize :set_defaults def set_defaults self.status ||= READY end end end end