Class: Spree::InventoryUnit
- Defined in:
- app/models/spree/inventory_unit.rb
Class Method Summary collapse
-
.backordered_for_stock_item(stock_item) ⇒ Object
This was refactored from a simpler query because the previous implementation lead to issues once users tried to modify the objects returned.
- .finalize_units!(inventory_units) ⇒ Object
Instance Method Summary collapse
- #find_stock_item ⇒ Object
-
#variant ⇒ Object
Remove variant default_scope ‘deleted_at: nil`.
Methods inherited from Base
Methods included from Preferences::Preferable
#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Class Method Details
.backordered_for_stock_item(stock_item) ⇒ Object
This was refactored from a simpler query because the previous implementation lead to issues once users tried to modify the objects returned. That’s due to ActiveRecord ‘joins(shipment: :stock_location)` only return readonly objects
Returns an array of backordered inventory units as per a given stock item
41 42 43 44 45 |
# File 'app/models/spree/inventory_unit.rb', line 41 def self.backordered_for_stock_item(stock_item) backordered_per_variant(stock_item).select do |unit| unit.shipment.stock_location == stock_item.stock_location end end |
.finalize_units!(inventory_units) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'app/models/spree/inventory_unit.rb', line 47 def self.finalize_units!(inventory_units) inventory_units.map do |iu| iu.update_columns( pending: false, updated_at: Time.now, ) end end |