Class: InventoryEntry

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/inventory_entry.rb

Instance Method Summary collapse

Instance Method Details

#current_locationObject



25
26
27
# File 'app/models/inventory_entry.rb', line 25

def current_location
  self.inventory_entry_locations
end

#current_storage_facilityObject



29
30
31
# File 'app/models/inventory_entry.rb', line 29

def current_storage_facility
  inventory_entry_locations.last.facility
end

#current_storage_facility=(facility) ⇒ Object



33
34
35
36
37
38
# File 'app/models/inventory_entry.rb', line 33

def current_storage_facility=(facility)
  location = InventoryEntryLocation.new
  location.facility = facility
  location.inventory_entry = self
  location.save
end

#current_storage_facility_id=(facility_id) ⇒ Object



40
41
42
43
44
45
# File 'app/models/inventory_entry.rb', line 40

def current_storage_facility_id=(facility_id)
  location = InventoryEntryLocation.new
  location.facility_id = facility_id
  location.inventory_entry = self
  location.save
end

#get_skuObject



78
79
80
81
82
83
84
# File 'app/models/inventory_entry.rb', line 78

def get_sku
  if self.sku.blank? and self.product_type
    self.product_type_sku
  else
    self.sku
  end
end

#get_uomObject



86
87
88
89
90
91
92
# File 'app/models/inventory_entry.rb', line 86

def get_uom
  if self.unit_of_measurement.nil? and self.product_type
    self.product_type_unit_of_measurement
  else
    self.unit_of_measurement
  end
end

#to_data_hashObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/inventory_entry.rb', line 47

def to_data_hash
  data = to_hash(only: [
                     :id,
                     :description,
                     :number_available,
                     :number_in_stock,
                     :created_at,
                     :updated_at
                 ],
                 sku: get_sku,
                 product_type: try(:product_type).try(:to_data_hash))

  if get_uom
    data[:unit_of_measurement] = get_uom.to_data_hash
  else
    data[:unit_of_measurement] = nil
  end

  if current_storage_facility
    data[:inventory_storage_facility] = current_storage_facility.to_data_hash
  else
    data[:inventory_storage_facility] = nil
  end

  data
end

#to_labelObject



74
75
76
# File 'app/models/inventory_entry.rb', line 74

def to_label
  "#{description}"
end