parent
a6646d06a6
commit
55d2976e98
3 changed files with 30 additions and 26 deletions
|
@ -95,7 +95,7 @@ class OrdersController < ApplicationController
|
||||||
def finish
|
def finish
|
||||||
order = Order.find(params[:id])
|
order = Order.find(params[:id])
|
||||||
order.finish!(@current_user)
|
order.finish!(@current_user)
|
||||||
call_rake "foodsoft:notify_order_finished", :order_id => order.id
|
call_rake "foodsoft:finished_order_tasks", :order_id => order.id
|
||||||
flash[:notice] = "Die Bestellung wurde beendet."
|
flash[:notice] = "Die Bestellung wurde beendet."
|
||||||
redirect_to order
|
redirect_to order
|
||||||
end
|
end
|
||||||
|
|
|
@ -174,20 +174,6 @@ class Order < ActiveRecord::Base
|
||||||
|
|
||||||
# set new order state (needed by notify_order_finished)
|
# set new order state (needed by notify_order_finished)
|
||||||
update_attributes(:state => 'finished', :ends => Time.now, :updated_by => user)
|
update_attributes(:state => 'finished', :ends => Time.now, :updated_by => user)
|
||||||
|
|
||||||
# Update GroupOrder prices
|
|
||||||
group_orders.each { |go| go.update_price! }
|
|
||||||
|
|
||||||
# Clean up
|
|
||||||
# Delete no longer required order-history (group_order_article_quantities) and
|
|
||||||
# TODO: Do we need articles, which aren't ordered? (units_to_order == 0 ?)
|
|
||||||
order_articles.each do |oa|
|
|
||||||
oa.group_order_articles.each { |goa| goa.group_order_article_quantities.clear }
|
|
||||||
end
|
|
||||||
|
|
||||||
# Stats
|
|
||||||
# TODO: Move into background, if possible
|
|
||||||
ordergroups.each { |o| o.update_stats! }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -68,13 +68,31 @@ namespace :foodsoft do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "Notify users of finished orders"
|
desc "finished order tasks, cleanup, notifications, stats ..."
|
||||||
task :notify_order_finished => :environment do
|
task :finished_order_tasks => :environment do
|
||||||
|
puts "Start: #{Time.now}"
|
||||||
order = Order.find(ENV["ORDER_ID"])
|
order = Order.find(ENV["ORDER_ID"])
|
||||||
|
|
||||||
|
# Update GroupOrder prices
|
||||||
|
order.group_orders.each { |go| go.update_price! }
|
||||||
|
|
||||||
|
# Clean up
|
||||||
|
# Delete no longer required order-history (group_order_article_quantities) and
|
||||||
|
# TODO: Do we need articles, which aren't ordered? (units_to_order == 0 ?)
|
||||||
|
order.order_articles.each do |oa|
|
||||||
|
oa.group_order_articles.each { |goa| goa.group_order_article_quantities.clear }
|
||||||
|
end
|
||||||
|
|
||||||
|
# Notifications
|
||||||
for group_order in order.group_orders
|
for group_order in order.group_orders
|
||||||
for user in group_order.ordergroup.users
|
for user in group_order.ordergroup.users
|
||||||
Mailer.deliver_order_result(user, group_order) if user.settings["notify.orderFinished"] == '1'
|
Mailer.deliver_order_result(user, group_order) if user.settings["notify.orderFinished"] == '1'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Stats
|
||||||
|
order.ordergroups.each { |o| o.update_stats! }
|
||||||
|
|
||||||
|
puts "End: #{Time.now}"
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue