Class: Spree::Stock::Allocator::OnHandFirst

Inherits:
Base
  • Object
show all
Defined in:
app/models/spree/stock/allocator/on_hand_first.rb

Instance Attribute Summary

Attributes inherited from Base

#availability

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Spree::Stock::Allocator::Base

Instance Method Details

#allocate_inventory(desired) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/spree/stock/allocator/on_hand_first.rb', line 7

def allocate_inventory(desired)
  # Allocate any available on hand inventory
  on_hand = allocate_on_hand(desired)
  desired -= on_hand.values.reduce(&:+) if on_hand.present?

  # Allocate remaining desired inventory from backorders
  backordered = allocate_backordered(desired)
  desired -= backordered.values.reduce(&:+) if backordered.present?

  # If all works at this point desired must be empty
  [on_hand, backordered, desired]
end