Class: Spree::Stock::Packer
- Inherits:
-
Object
- Object
- Spree::Stock::Packer
- Defined in:
- app/models/spree/stock/packer.rb
Instance Attribute Summary collapse
-
#inventory_units ⇒ Object
readonly
Returns the value of attribute inventory_units.
-
#splitters ⇒ Object
readonly
Returns the value of attribute splitters.
-
#stock_location ⇒ Object
readonly
Returns the value of attribute stock_location.
Instance Method Summary collapse
- #default_package ⇒ Object
-
#initialize(stock_location, inventory_units, splitters = [Splitter::Base]) ⇒ Packer
constructor
A new instance of Packer.
- #packages ⇒ Object
Constructor Details
#initialize(stock_location, inventory_units, splitters = [Splitter::Base]) ⇒ Packer
Returns a new instance of Packer.
6 7 8 9 10 |
# File 'app/models/spree/stock/packer.rb', line 6 def initialize(stock_location, inventory_units, splitters = [Splitter::Base]) @stock_location = stock_location @inventory_units = inventory_units @splitters = splitters end |
Instance Attribute Details
#inventory_units ⇒ Object (readonly)
Returns the value of attribute inventory_units.
4 5 6 |
# File 'app/models/spree/stock/packer.rb', line 4 def inventory_units @inventory_units end |
#splitters ⇒ Object (readonly)
Returns the value of attribute splitters.
4 5 6 |
# File 'app/models/spree/stock/packer.rb', line 4 def splitters @splitters end |
#stock_location ⇒ Object (readonly)
Returns the value of attribute stock_location.
4 5 6 |
# File 'app/models/spree/stock/packer.rb', line 4 def stock_location @stock_location end |
Instance Method Details
#default_package ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/spree/stock/packer.rb', line 20 def default_package package = Package.new(stock_location) # Group by variant_id as grouping by variant fires cached query. inventory_units.index_by(&:variant_id).each do |variant_id, inventory_unit| variant = Spree::Variant.find(variant_id) unit = inventory_unit.dup # Can be used by others, do not use directly if variant.should_track_inventory? next unless stock_location.stocks? variant on_hand, backordered = stock_location.fill_status(variant, unit.quantity) package.add(InventoryUnit.split(unit, backordered), :backordered) if backordered.positive? package.add(InventoryUnit.split(unit, on_hand), :on_hand) if on_hand.positive? else package.add unit end end package end |
#packages ⇒ Object
12 13 14 15 16 17 18 |
# File 'app/models/spree/stock/packer.rb', line 12 def packages if splitters.empty? [default_package] else build_splitter.split [default_package] end end |