Class: StorageLocation

Inherits:
ApplicationRecord show all
Defined in:
app/models/storage_location.rb

Overview

== Schema Information

Table name: storage_locations
Database name: primary

id :bigint not null, primary key
aisle :integer not null
bin :integer not null
level :integer not null
notes :text
reference_number :string not null
section :integer not null
zone :string not null
store_id :integer not null

Indexes

idx_sl_aisle (aisle)
idx_sl_bin (bin)
idx_sl_level (level)
idx_sl_section (section)
idx_sl_zone (zone)
index_storage_locations_on_reference_number (store_id,reference_number) UNIQUE

Foreign Keys

fk_rails_... (store_id => stores.id)

Constant Summary collapse

ZONES =
('A'..'Z').to_a.freeze

Instance Attribute Summary collapse

Belongs to collapse

Has and belongs to many collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#aisleObject (readonly)



43
# File 'app/models/storage_location.rb', line 43

validates :aisle, presence: true, numericality: { only_integer: true, greater_than: 0 }

#binObject (readonly)



46
# File 'app/models/storage_location.rb', line 46

validates :bin, presence: true, numericality: { only_integer: true, greater_than: 0 }

#levelObject (readonly)



45
# File 'app/models/storage_location.rb', line 45

validates :level, presence: true, numericality: { only_integer: true, greater_than: 0 }

#reference_numberObject (readonly)



41
# File 'app/models/storage_location.rb', line 41

validates :reference_number, uniqueness: { scope: :store_id }

#sectionObject (readonly)



44
# File 'app/models/storage_location.rb', line 44

validates :section, presence: true, numericality: { only_integer: true, greater_than: 0 }

#zoneObject (readonly)



42
# File 'app/models/storage_location.rb', line 42

validates :zone, presence: true, inclusion: { in: ZONES }

Class Method Details

.select_options(store) ⇒ Object



52
53
54
# File 'app/models/storage_location.rb', line 52

def self.select_options(store)
  store.storage_locations.order(:reference_number).pluck(:reference_number, :id)
end

Instance Method Details

#cycle_count_itemsActiveRecord::Relation<CycleCountItem>

Returns:

See Also:



35
# File 'app/models/storage_location.rb', line 35

has_and_belongs_to_many :cycle_count_items

#format_reference_numberObject



80
81
82
# File 'app/models/storage_location.rb', line 80

def format_reference_number
  index_fields.map{|f| send("formatted_#{f}".to_sym)}.join('.')
end

#formatted_aisleObject



60
61
62
# File 'app/models/storage_location.rb', line 60

def formatted_aisle
  'A%02i' % aisle
end

#formatted_binObject



72
73
74
# File 'app/models/storage_location.rb', line 72

def formatted_bin
  'B%02i' % bin
end

#formatted_levelObject



68
69
70
# File 'app/models/storage_location.rb', line 68

def formatted_level
  'L%02i' % level
end

#formatted_sectionObject



64
65
66
# File 'app/models/storage_location.rb', line 64

def formatted_section
  'S%02i' % section
end

#formatted_zoneObject



56
57
58
# File 'app/models/storage_location.rb', line 56

def formatted_zone
  zone
end

#index_fieldsObject



76
77
78
# File 'app/models/storage_location.rb', line 76

def index_fields
  %i[zone aisle section level bin]
end

#storeStore

Returns:

See Also:



33
# File 'app/models/storage_location.rb', line 33

belongs_to :store

#store_itemsActiveRecord::Relation<StoreItem>

Returns:

See Also:



34
# File 'app/models/storage_location.rb', line 34

has_and_belongs_to_many :store_items

#to_sObject



48
49
50
# File 'app/models/storage_location.rb', line 48

def to_s
  reference_number
end