mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
23 lines
436 B
Ruby
23 lines
436 B
Ruby
require 'active_support/concern'
|
|
|
|
module ProductStock
|
|
extend ActiveSupport::Concern
|
|
|
|
def on_demand
|
|
if has_variants?
|
|
raise 'Cannot determine product on_demand value of product with multiple variants' if variants.size > 1
|
|
variants.first.on_demand
|
|
else
|
|
master.on_demand
|
|
end
|
|
end
|
|
|
|
def on_hand
|
|
if has_variants?
|
|
variants.map(&:on_hand).reduce(:+)
|
|
else
|
|
master.on_hand
|
|
end
|
|
end
|
|
end
|