Files
openfoodnetwork/app/services/default_stock_location.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

23 lines
713 B
Ruby

# frozen_string_literal: true
# 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'
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