2009-01-06 11:49:19 +01:00
|
|
|
# put in here all foodsoft tasks
|
|
|
|
# => :environment loads the environment an gives easy access to the application
|
|
|
|
|
|
|
|
namespace :foodsoft do
|
2009-02-10 15:07:47 +01:00
|
|
|
desc "Notify users of upcoming tasks"
|
|
|
|
task :notify_upcoming_tasks => :environment do
|
|
|
|
tasks = Task.find :all, :conditions => ["done = ? AND due_date = ?", false, 1.day.from_now.to_date]
|
|
|
|
for task in tasks
|
|
|
|
puts "Send notifications for #{task.name} to .."
|
|
|
|
for user in task.users
|
|
|
|
if user.settings['notify.upcoming_tasks'] == 1
|
2010-03-20 23:07:55 +01:00
|
|
|
begin
|
|
|
|
puts "#{user.email}.."
|
|
|
|
Mailer.deliver_upcoming_tasks(user, task)
|
|
|
|
rescue
|
|
|
|
puts "deliver aborted for #{user.email}.."
|
|
|
|
end
|
2009-02-10 15:07:47 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-03-11 16:58:31 +01:00
|
|
|
|
2009-08-11 17:17:18 +02:00
|
|
|
desc "Create upcoming workgroups tasks (next 3 to 7 weeks)"
|
|
|
|
task :create_upcoming_weekly_tasks => :environment do
|
|
|
|
workgroups = Workgroup.all :conditions => {:weekly_task => true}
|
|
|
|
for workgroup in workgroups
|
|
|
|
puts "Create weekly tasks for #{workgroup.name}"
|
2012-06-26 23:18:55 +02:00
|
|
|
# Loop through next tasks weekly tasks method,
|
|
|
|
# skip the next 3 weeks, to allow manually deleting tasks
|
|
|
|
workgroup.next_weekly_tasks[3..-1].each do |date|
|
2009-08-11 17:17:18 +02:00
|
|
|
unless workgroup.tasks.exists?({:due_date => date, :weekly => true})
|
|
|
|
workgroup.tasks.create(workgroup.task_attributes(date))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-11 18:10:14 +02:00
|
|
|
desc "Notify workgroup of upcoming weekly task"
|
|
|
|
task :notify_users_of_weekly_task => :environment do
|
|
|
|
for workgroup in Workgroup.all
|
2009-08-12 21:47:07 +02:00
|
|
|
for task in workgroup.tasks.all(:conditions => ["due_date = ?", 7.days.from_now.to_date])
|
2009-08-11 18:10:14 +02:00
|
|
|
unless task.enough_users_assigned?
|
|
|
|
puts "Notify workgroup: #{workgroup.name} for task #{task.name}"
|
2009-08-14 13:50:05 +02:00
|
|
|
for user in workgroup.users
|
|
|
|
if user.settings['messages.sendAsEmail'] == "1" && !user.email.blank?
|
2010-03-20 23:07:55 +01:00
|
|
|
begin
|
|
|
|
Mailer.deliver_not_enough_users_assigned(task, user)
|
|
|
|
rescue
|
|
|
|
puts "deliver aborted for #{user.email}"
|
|
|
|
end
|
2009-08-14 13:50:05 +02:00
|
|
|
end
|
2009-08-11 18:10:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-02-09 21:45:57 +01:00
|
|
|
desc "finished order tasks, cleanup, notifications, stats ..."
|
|
|
|
task :finished_order_tasks => :environment do
|
|
|
|
puts "Start: #{Time.now}"
|
2009-03-11 16:58:31 +01:00
|
|
|
order = Order.find(ENV["ORDER_ID"])
|
2010-02-09 21:45:57 +01:00
|
|
|
|
|
|
|
# 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
|
2009-03-11 16:58:31 +01:00
|
|
|
for group_order in order.group_orders
|
|
|
|
for user in group_order.ordergroup.users
|
2010-03-20 23:07:55 +01:00
|
|
|
begin
|
|
|
|
Mailer.deliver_order_result(user, group_order) if user.settings["notify.orderFinished"] == '1'
|
|
|
|
rescue
|
|
|
|
puts "deliver aborted for #{user.email}.."
|
|
|
|
end
|
2009-03-11 16:58:31 +01:00
|
|
|
end
|
|
|
|
end
|
2010-02-09 21:45:57 +01:00
|
|
|
|
|
|
|
# Stats
|
|
|
|
order.ordergroups.each { |o| o.update_stats! }
|
|
|
|
|
|
|
|
puts "End: #{Time.now}"
|
2009-03-11 16:58:31 +01:00
|
|
|
end
|
2010-03-20 23:07:55 +01:00
|
|
|
end
|