parent
a6646d06a6
commit
55d2976e98
3 changed files with 30 additions and 26 deletions
|
@ -95,7 +95,7 @@ class OrdersController < ApplicationController
|
|||
def finish
|
||||
order = Order.find(params[:id])
|
||||
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."
|
||||
redirect_to order
|
||||
end
|
||||
|
|
|
@ -51,14 +51,14 @@ class Order < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def articles_for_ordering
|
||||
if stockit?
|
||||
StockArticle.available.without_deleted(:include => :article_category,
|
||||
:order => 'article_categories.name, articles.name').reject{ |a|
|
||||
a.quantity_available <= 0
|
||||
}.group_by { |a| a.article_category.name }
|
||||
else
|
||||
supplier.articles.available.without_deleted.group_by { |a| a.article_category.name }
|
||||
end
|
||||
if stockit?
|
||||
StockArticle.available.without_deleted(:include => :article_category,
|
||||
:order => 'article_categories.name, articles.name').reject{ |a|
|
||||
a.quantity_available <= 0
|
||||
}.group_by { |a| a.article_category.name }
|
||||
else
|
||||
supplier.articles.available.without_deleted.group_by { |a| a.article_category.name }
|
||||
end
|
||||
end
|
||||
|
||||
# Fetch last orders from same supplier, to generate an article selection proposal
|
||||
|
@ -174,20 +174,6 @@ class Order < ActiveRecord::Base
|
|||
|
||||
# set new order state (needed by notify_order_finished)
|
||||
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
|
||||
|
@ -220,7 +206,7 @@ class Order < ActiveRecord::Base
|
|||
protected
|
||||
|
||||
def starts_before_ends
|
||||
errors.add(:ends, "muss nach dem Bestellstart liegen (oder leer bleiben)") if (ends && starts && ends <= starts)
|
||||
errors.add(:ends, "muss nach dem Bestellstart liegen (oder leer bleiben)") if (ends && starts && ends <= starts)
|
||||
end
|
||||
|
||||
def include_articles
|
||||
|
|
|
@ -68,13 +68,31 @@ namespace :foodsoft do
|
|||
end
|
||||
end
|
||||
|
||||
desc "Notify users of finished orders"
|
||||
task :notify_order_finished => :environment do
|
||||
desc "finished order tasks, cleanup, notifications, stats ..."
|
||||
task :finished_order_tasks => :environment do
|
||||
puts "Start: #{Time.now}"
|
||||
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 user in group_order.ordergroup.users
|
||||
Mailer.deliver_order_result(user, group_order) if user.settings["notify.orderFinished"] == '1'
|
||||
end
|
||||
end
|
||||
|
||||
# Stats
|
||||
order.ordergroups.each { |o| o.update_stats! }
|
||||
|
||||
puts "End: #{Time.now}"
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue