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 =

Zones.

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

Constants included from Schedulable

Schedulable::SIMPLE_FORM_OPTIONS

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 Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#aisleObject (readonly)



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

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

#binObject (readonly)



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

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

#levelObject (readonly)



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

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

#reference_numberObject (readonly)



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

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

#sectionObject (readonly)



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

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

#zoneObject (readonly)



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

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

Class Method Details

.select_options(store) ⇒ Object



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

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:



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

has_and_belongs_to_many :cycle_count_items

#format_reference_numberObject



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

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

#formatted_aisleObject



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

def formatted_aisle
  'A%02i' % aisle
end

#formatted_binObject



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

def formatted_bin
  'B%02i' % bin
end

#formatted_levelObject



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

def formatted_level
  'L%02i' % level
end

#formatted_sectionObject



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

def formatted_section
  'S%02i' % section
end

#formatted_zoneObject



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

def formatted_zone
  zone
end

#index_fieldsObject



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

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

#storeStore

Returns:

See Also:



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

belongs_to :store

#store_itemsActiveRecord::Relation<StoreItem>

Returns:

See Also:



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

has_and_belongs_to_many :store_items

#to_sObject



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

def to_s
  reference_number
end