Class: Stockman::Logic::Product::StockLevel

Inherits:
Object
  • Object
show all
Defined in:
lib/stockman/logic/product/stock_level.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sellables, warehouse_id) ⇒ StockLevel



7
8
9
10
# File 'lib/stockman/logic/product/stock_level.rb', line 7

def initialize(sellables, warehouse_id)
  @sellables    = sellables
  @warehouse_id = warehouse_id.to_i
end

Instance Attribute Details

#sellablesObject (readonly)

Returns the value of attribute sellables.



5
6
7
# File 'lib/stockman/logic/product/stock_level.rb', line 5

def sellables
  @sellables
end

#warehouse_idObject (readonly)

Returns the value of attribute warehouse_id.



5
6
7
# File 'lib/stockman/logic/product/stock_level.rb', line 5

def warehouse_id
  @warehouse_id
end

Instance Method Details

#allocated_amountObject



16
17
18
# File 'lib/stockman/logic/product/stock_level.rb', line 16

def allocated_amount
  sellables_stock_levels.sum(&:allocated_amount)
end

#available_amountObject



20
21
22
# File 'lib/stockman/logic/product/stock_level.rb', line 20

def available_amount
  sellables_stock_levels.sum(&:available_amount)
end

#physical_amountObject



12
13
14
# File 'lib/stockman/logic/product/stock_level.rb', line 12

def physical_amount
  sellables_stock_levels.sum(&:physical_amount)
end

#sellables_stock_levelsObject



24
25
26
27
28
# File 'lib/stockman/logic/product/stock_level.rb', line 24

def sellables_stock_levels
  @sellables_stock_levels ||= sellables.stock_levels.select do |stock_level|
    stock_level.warehouse_id == warehouse_id
  end
end