Files
openfoodnetwork/app/models/concerns/product_stock.rb
Luis Ramos e52937c113 Use rubocop auto correct to add frozen string literal to all files
This is an unsafe auto corection, we will need to trust our build here
2021-06-17 23:07:26 +01:00

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