Class: Spree::InventoryUnit
- Inherits:
-
Base
- Object
- ActiveRecord::Base
- Base
- Spree::InventoryUnit
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
#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
49
50
51
52
53
|
# File 'app/models/spree/inventory_unit.rb', line 49
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
55
56
57
58
59
60
61
62
|
# File 'app/models/spree/inventory_unit.rb', line 55
def self.finalize_units!(inventory_units)
inventory_units.map do |iu|
iu.update_columns(
pending: false,
updated_at: Time.current,
)
end
end
|
Instance Method Details
#additional_tax_total ⇒ Object
78
79
80
|
# File 'app/models/spree/inventory_unit.rb', line 78
def additional_tax_total
line_item.additional_tax_total * percentage_of_line_item
end
|
#current_or_new_return_item ⇒ Object
#find_stock_item ⇒ Object
64
65
66
67
|
# File 'app/models/spree/inventory_unit.rb', line 64
def find_stock_item
Spree::StockItem.where(stock_location_id: shipment.stock_location_id,
variant_id: variant_id).first
end
|
#included_tax_total ⇒ Object
82
83
84
|
# File 'app/models/spree/inventory_unit.rb', line 82
def included_tax_total
line_item.included_tax_total * percentage_of_line_item
end
|
#variant ⇒ Object
Remove variant default_scope ‘deleted_at: nil`
70
71
72
|
# File 'app/models/spree/inventory_unit.rb', line 70
def variant
Spree::Variant.unscoped { super }
end
|