Files
openfoodnetwork/lib/tasks/sample_data/inventory_factory.rb
Maikel Linke c3029c612a Fix sample product creation and use bang methods
Mistakes like the missing fee when creating product distributions were
hidden, because I didn't use the bang methods to create records.
2019-02-05 16:23:17 +11:00

35 lines
815 B
Ruby

require "tasks/sample_data/logging"
class InventoryFactory
include Logging
def create_samples(products)
log "Creating inventories"
marys_shop = Enterprise.find_by_name("Mary's Online Shop")
products.each do |product|
create_item(marys_shop, product)
end
end
private
def create_item(shop, product)
InventoryItem.create_with(
enterprise: shop,
variant: product.variants.first,
visible: true
).find_or_create_by_variant_id!(product.variants.first.id)
create_override(shop, product)
end
def create_override(shop, product)
VariantOverride.create_with(
variant: product.variants.first,
hub: shop,
price: 12,
on_demand: false,
count_on_hand: 5
).find_or_create_by_variant_id!(product.variants.first.id)
end
end