2014-04-08 13:11:06 +02:00
|
|
|
# only works properly for open orders, at the moment
|
|
|
|
def seed_group_orders
|
|
|
|
Order.all.each do |order|
|
|
|
|
noas = order.order_articles.count
|
|
|
|
Ordergroup.all.each do |og|
|
|
|
|
# 20% of the order-ordergroup combinations don't order
|
|
|
|
next if rand(10) < 2
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2014-04-08 13:11:06 +02:00
|
|
|
# order 3..12 times a random article
|
2020-10-11 13:28:09 +02:00
|
|
|
go = og.group_orders.create!(order: order, updated_by_user_id: 1)
|
2023-05-12 13:01:12 +02:00
|
|
|
rand(3..12).times do
|
2020-10-10 19:40:37 +02:00
|
|
|
goa = go.group_order_articles.find_or_create_by!(order_article: order.order_articles.offset(rand(noas)).first)
|
2014-04-08 13:11:06 +02:00
|
|
|
unit_quantity = goa.order_article.price.unit_quantity
|
2023-05-12 13:01:12 +02:00
|
|
|
goa.update_quantities rand([4, (unit_quantity * 2) + 2].max), rand(unit_quantity)
|
2014-04-08 13:11:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
# update totals
|
|
|
|
order.order_articles.map(&:update_results!)
|
|
|
|
order.group_orders.map(&:update_price!)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-01 15:27:26 +01:00
|
|
|
def seed_order(options = {})
|
|
|
|
options[:article_ids] ||= (options[:supplier] || Supplier.find(options[:supplier_id])).articles.map(&:id)
|
2014-04-08 13:11:06 +02:00
|
|
|
options[:created_by_user_id] ||= 1
|
2020-10-11 13:28:09 +02:00
|
|
|
options[:updated_by_user_id] ||= 1
|
2020-10-10 19:40:37 +02:00
|
|
|
Order.create! options
|
2014-04-08 13:11:06 +02:00
|
|
|
end
|