Class: Spree::StockItem
- Includes:
- SoftDeletable
- Defined in:
- app/models/spree/stock_item.rb
Instance Method Summary collapse
-
#adjust_count_on_hand(value) ⇒ Object
Adjusts the count on hand by a given value.
-
#available? ⇒ Boolean
True if this stock item can be included in a shipment.
-
#backordered_inventory_units ⇒ Array<Spree::InventoryUnit>
The backordered inventory units associated with this stock item.
- #fill_status(quantity) ⇒ Object
-
#in_stock? ⇒ Boolean
True if this stock item’s count on hand is not zero.
-
#name ⇒ String
The name of this stock item’s variant.
-
#reduce_count_on_hand_to_zero ⇒ Object
Sets the count on hand to zero if it not already zero.
-
#set_count_on_hand(value) ⇒ Object
Sets this stock item’s count on hand.
Methods inherited from Base
Methods included from Core::Permalinks
#generate_permalink, #save_permalink
Instance Method Details
#adjust_count_on_hand(value) ⇒ Object
This will cause backorders to be processed.
Adjusts the count on hand by a given value.
37 38 39 40 41 42 43 44 |
# File 'app/models/spree/stock_item.rb', line 37 def adjust_count_on_hand(value) with_lock do self.count_on_hand = count_on_hand + value process_backorders(count_on_hand - count_on_hand_was) save! end end |
#available? ⇒ Boolean
Returns true if this stock item can be included in a shipment.
63 64 65 |
# File 'app/models/spree/stock_item.rb', line 63 def available? in_stock? || backorderable? end |
#backordered_inventory_units ⇒ Array<Spree::InventoryUnit>
Returns the backordered inventory units associated with this stock item.
28 29 30 |
# File 'app/models/spree/stock_item.rb', line 28 def backordered_inventory_units Spree::InventoryUnit.backordered_for_stock_item(self) end |
#fill_status(quantity) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/models/spree/stock_item.rb', line 74 def fill_status(quantity) if count_on_hand >= quantity on_hand = quantity backordered = 0 else on_hand = count_on_hand on_hand = 0 if on_hand < 0 backordered = backorderable? ? (quantity - on_hand) : 0 end [on_hand, backordered] end |
#in_stock? ⇒ Boolean
Returns true if this stock item’s count on hand is not zero.
58 59 60 |
# File 'app/models/spree/stock_item.rb', line 58 def in_stock? count_on_hand > 0 end |
#name ⇒ String
Returns the name of this stock item’s variant.
18 |
# File 'app/models/spree/stock_item.rb', line 18 delegate :name, to: :variant, prefix: true |
#reduce_count_on_hand_to_zero ⇒ Object
This processes backorders if the count on hand is not zero.
Sets the count on hand to zero if it not already zero.
70 71 72 |
# File 'app/models/spree/stock_item.rb', line 70 def reduce_count_on_hand_to_zero set_count_on_hand(0) if count_on_hand > 0 end |
#set_count_on_hand(value) ⇒ Object
This will cause backorders to be processed.
Sets this stock item’s count on hand.
50 51 52 53 54 55 |
# File 'app/models/spree/stock_item.rb', line 50 def set_count_on_hand(value) self.count_on_hand = value process_backorders(count_on_hand - count_on_hand_was) save! end |