Class: Spree::InventoryUnit

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

page, spree_base_scopes

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 led to issues once users tried to modify the objects returned. That’s due to ActiveRecord ‘joins(shipment: :stock_location)` only returning readonly objects

Returns an array of backordered inventory units as per a given stock item



50
51
52
53
54
# File 'app/models/spree/inventory_unit.rb', line 50

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!Object



56
57
58
# File 'app/models/spree/inventory_unit.rb', line 56

def self.finalize_units!
  update_all(pending: false, updated_at: Time.current)
end

Instance Method Details

#additional_tax_totalObject



74
75
76
# File 'app/models/spree/inventory_unit.rb', line 74

def additional_tax_total
  line_item.additional_tax_total * percentage_of_line_item
end

#current_or_new_return_itemObject



70
71
72
# File 'app/models/spree/inventory_unit.rb', line 70

def current_or_new_return_item
  Spree::ReturnItem.from_inventory_unit(self)
end

#find_stock_itemObject



60
61
62
63
# File 'app/models/spree/inventory_unit.rb', line 60

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

#included_tax_totalObject



78
79
80
# File 'app/models/spree/inventory_unit.rb', line 78

def included_tax_total
  line_item.included_tax_total * percentage_of_line_item
end

#variantObject

Remove variant default_scope ‘deleted_at: nil`



66
67
68
# File 'app/models/spree/inventory_unit.rb', line 66

def variant
  Spree::Variant.unscoped { super }
end