mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-28 21:07:16 +00:00
Bring Spree::Stock::Quantifier in to OFN
This is the original unmodified Class from Spree. Modifications added in subsequent commits.
This commit is contained in:
28
app/models/spree/stock/quantifier.rb
Normal file
28
app/models/spree/stock/quantifier.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
module Spree
|
||||
module Stock
|
||||
class Quantifier
|
||||
attr_reader :stock_items
|
||||
|
||||
def initialize(variant)
|
||||
@variant = variant
|
||||
@stock_items = Spree::StockItem.joins(:stock_location).where(:variant_id => @variant, Spree::StockLocation.table_name =>{ :active => true})
|
||||
end
|
||||
|
||||
def total_on_hand
|
||||
if Spree::Config.track_inventory_levels
|
||||
stock_items.sum(&:count_on_hand)
|
||||
else
|
||||
Float::INFINITY
|
||||
end
|
||||
end
|
||||
|
||||
def backorderable?
|
||||
stock_items.any?(&:backorderable)
|
||||
end
|
||||
|
||||
def can_supply?(required)
|
||||
total_on_hand >= required || backorderable?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user