Class: Spree::InventoryUnit

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/spree/inventory_unit.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.backordered_for_stock_item(stock_item) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'app/models/spree/inventory_unit.rb', line 29

def self.backordered_for_stock_item(stock_item)
  stock_locations_table = Spree::StockLocation.table_name
  shipments_table = Spree::Shipment.table_name
  joins(shipment: :stock_location).
  where("#{stock_locations_table}.id = ?", stock_item.stock_location_id).
  where(variant_id: stock_item.variant_id).
  where("#{shipments_table}.state != 'canceled'").
  backordered.order('created_at ASC')
end

.finalize_units!(inventory_units) ⇒ Object



39
40
41
# File 'app/models/spree/inventory_unit.rb', line 39

def self.finalize_units!(inventory_units)
  inventory_units.map { |iu| iu.update_column(:pending, false) }
end

Instance Method Details

#find_stock_itemObject



43
44
45
46
# File 'app/models/spree/inventory_unit.rb', line 43

def find_stock_item
  Spree::StockItem.where(stock_location_id: shipment.stock_location_id,
    variant_id: variant_id).first
end