mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-14 23:47:48 +00:00
26 lines
460 B
Ruby
26 lines
460 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'active_support/concern'
|
|
|
|
module ProductStock
|
|
extend ActiveSupport::Concern
|
|
|
|
def on_demand
|
|
if 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 variants?
|
|
variants.map(&:on_hand).reduce(:+)
|
|
else
|
|
master.on_hand
|
|
end
|
|
end
|
|
end
|