Send order-finish-notifications in background.
This commit is contained in:
parent
37c9e2aeaf
commit
ce2156d75f
4 changed files with 14 additions and 15 deletions
|
@ -95,6 +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
|
||||||
flash[:notice] = "Die Bestellung wurde beendet."
|
flash[:notice] = "Die Bestellung wurde beendet."
|
||||||
redirect_to order
|
redirect_to order
|
||||||
end
|
end
|
||||||
|
|
|
@ -183,9 +183,6 @@ class Order < ActiveRecord::Base
|
||||||
oa.group_order_articles.each { |goa| goa.group_order_article_quantities.clear }
|
oa.group_order_articles.each { |goa| goa.group_order_article_quantities.clear }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# notify order groups
|
|
||||||
notify_order_finished
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -232,13 +229,4 @@ class Order < ActiveRecord::Base
|
||||||
group_orders.each { |group_order| group_order.update_price! }
|
group_orders.each { |group_order| group_order.update_price! }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sends "order finished" messages to users who have participated in this order.
|
|
||||||
def notify_order_finished
|
|
||||||
for group_order in self.group_orders
|
|
||||||
for user in group_order.ordergroup.users
|
|
||||||
Mailer.deliver_order_result(user, group_order) if user.settings["notify.orderFinished"] == '1'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,9 +3,9 @@ Liebe <%= @group_order.ordergroup.name %>,
|
||||||
die Bestellung für "<%= @order.name %>" wurde am <%= @order.ends.strftime('%d.%m.%Y um %H:%M') %> von <%= @order.updated_by.nick %> beendet.
|
die Bestellung für "<%= @order.name %>" wurde am <%= @order.ends.strftime('%d.%m.%Y um %H:%M') %> von <%= @order.updated_by.nick %> beendet.
|
||||||
|
|
||||||
Für Euch wurden die folgenden Artikel bestellt:
|
Für Euch wurden die folgenden Artikel bestellt:
|
||||||
<% for group_order_article in @group_order.group_order_articles.all(:include => :order_article)
|
<% for group_order_article in @group_order.group_order_articles.ordered.all(:include => :order_article)
|
||||||
article = group_order_article.order_article.article -%>
|
article = group_order_article.order_article.article -%>
|
||||||
<%= article.name %>: <%= group_order_article.quantity %> x <%= article.unit %> = <%= group_order_article.quantity * article.fc_price %>
|
<%= article.name %>: <%= group_order_article.result %> x <%= article.unit %> = <%= group_order_article.result * article.fc_price %>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
Gesamtpreis: <%= @group_order.price %>
|
Gesamtpreis: <%= @group_order.price %>
|
||||||
|
|
||||||
|
|
|
@ -38,4 +38,14 @@ namespace :foodsoft do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
desc "Notify users of finished orders"
|
||||||
|
task :notify_order_finished => :environment do
|
||||||
|
order = Order.find(ENV["ORDER_ID"])
|
||||||
|
for group_order in order.group_orders
|
||||||
|
for user in group_order.ordergroup.users
|
||||||
|
Mailer.deliver_order_result(user, group_order) if user.settings["notify.orderFinished"] == '1'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue