Files
openfoodnetwork/app/services/default_stock_location.rb
luisramos0 f896e78e6f Set StockLocation.backorderable_default to false in DefaultStockLocation and in StockLocation factory.
This makes the default value of variant.on_demand false in all environments and in tests.

Additionally, adapt VariantStock.on_demand test and product factory to this change (setting on_hand value in product factory so it's not out of stock by default).
2019-01-17 20:28:05 +00:00

20 lines
654 B
Ruby

# Encapsulates the concept of default stock location that OFN has, as explained
# in https://github.com/openfoodfoundation/openfoodnetwork/wiki/Spree-Upgrade%3A-Stock-locations
class DefaultStockLocation
NAME = 'default'.freeze
def self.create!
country = Spree::Country.find_by_iso(ENV['DEFAULT_COUNTRY_CODE'])
state = country.states.first
Spree::StockLocation.create!(name: NAME, country_id: country.id, state_id: state.id, backorderable_default: false)
end
def self.destroy_all
Spree::StockLocation.where(name: NAME).destroy_all
end
def self.find_or_create
Spree::StockLocation.find_or_create_by_name(NAME)
end
end