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
|
2023-05-12 13:01:12 +02:00
|
|
|
desc 'Finish ended orders'
|
|
|
|
task finish_ended_orders: :environment do
|
2017-10-12 00:20:30 +02:00
|
|
|
Order.finish_ended!
|
|
|
|
end
|
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
desc 'Notify users of upcoming tasks'
|
|
|
|
task notify_upcoming_tasks: :environment do
|
2012-08-27 08:38:43 +02:00
|
|
|
tasks = Task.where(done: false, due_date: 1.day.from_now.to_date)
|
2009-02-10 15:07:47 +01:00
|
|
|
for task in tasks
|
2013-09-30 10:57:54 +02:00
|
|
|
rake_say "Send notifications for #{task.name} to .."
|
2009-02-10 15:07:47 +01:00
|
|
|
for user in task.users
|
2023-05-12 13:01:12 +02:00
|
|
|
next unless user.settings.notify['upcoming_tasks']
|
|
|
|
|
|
|
|
Mailer.deliver_now_with_user_locale user do
|
|
|
|
Mailer.upcoming_tasks(user, task)
|
2009-02-10 15:07:47 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-03-11 16:58:31 +01:00
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
desc 'Notify workgroup of upcoming weekly task'
|
|
|
|
task notify_users_of_weekly_task: :environment do
|
|
|
|
tasks = Task.where(done: false, due_date: 7.days.from_now.to_date)
|
2017-08-20 06:07:05 +02:00
|
|
|
for task in tasks
|
2023-05-12 13:01:12 +02:00
|
|
|
next if task.enough_users_assigned?
|
|
|
|
|
|
|
|
workgroup = task.workgroup
|
|
|
|
next unless workgroup
|
|
|
|
|
|
|
|
rake_say "Notify workgroup: #{workgroup.name} for task #{task.name}"
|
|
|
|
for user in workgroup.users
|
|
|
|
next unless user.receive_email?
|
|
|
|
|
|
|
|
Mailer.deliver_now_with_user_locale user do
|
|
|
|
Mailer.not_enough_users_assigned(task, user)
|
2009-08-11 18:10:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-11-28 10:13:54 +01:00
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
desc 'Create upcoming periodic tasks'
|
|
|
|
task create_upcoming_periodic_tasks: :environment do
|
2012-11-28 10:13:54 +01:00
|
|
|
for tg in PeriodicTaskGroup.all
|
2017-02-14 11:52:05 +01:00
|
|
|
created_until = tg.create_tasks_for_upfront_days
|
2016-02-24 20:47:09 +01:00
|
|
|
rake_say "created until #{created_until}"
|
2012-11-28 10:13:54 +01:00
|
|
|
end
|
|
|
|
end
|
2017-08-19 15:45:48 +02:00
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
desc 'Parse incoming email on stdin (options: RECIPIENT=foodcoop.handling)'
|
|
|
|
task parse_reply_email: :environment do
|
2022-05-27 21:57:06 +02:00
|
|
|
FoodsoftMailReceiver.received ENV.fetch('RECIPIENT', nil), STDIN.read
|
2017-08-19 15:45:48 +02:00
|
|
|
end
|
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
desc 'Start STMP server for incoming email (options: SMTP_SERVER_PORT=2525, SMTP_SERVER_HOST=0.0.0.0)'
|
|
|
|
task reply_email_smtp_server: :environment do
|
2017-08-19 15:45:48 +02:00
|
|
|
port = ENV['SMTP_SERVER_PORT'].present? ? ENV['SMTP_SERVER_PORT'].to_i : 2525
|
2022-05-27 21:57:06 +02:00
|
|
|
host = ENV.fetch('SMTP_SERVER_HOST', nil)
|
2017-08-19 15:45:48 +02:00
|
|
|
rake_say "Started SMTP server for incoming email on port #{port}."
|
2022-02-16 17:18:27 +01:00
|
|
|
server = FoodsoftMailReceiver.new(ports: port, hosts: host, max_processings: 1, logger: Rails.logger)
|
2017-08-19 15:45:48 +02:00
|
|
|
server.start
|
|
|
|
server.join
|
|
|
|
end
|
2017-01-17 23:12:31 +01:00
|
|
|
|
2023-05-12 13:01:12 +02:00
|
|
|
desc 'Import and assign bank transactions'
|
|
|
|
task import_and_assign_bank_transactions: :environment do
|
2017-01-17 23:12:31 +01:00
|
|
|
BankAccount.find_each do |ba|
|
2020-02-24 14:22:58 +01:00
|
|
|
importer = ba.find_connector
|
|
|
|
next unless importer
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2020-02-24 14:22:58 +01:00
|
|
|
importer.load nil
|
|
|
|
ok = importer.import nil
|
|
|
|
next unless ok
|
2021-03-01 15:27:26 +01:00
|
|
|
|
2020-02-24 14:22:58 +01:00
|
|
|
importer.finish
|
2017-01-17 23:12:31 +01:00
|
|
|
assign_count = ba.assign_unlinked_transactions
|
2020-02-24 14:22:58 +01:00
|
|
|
rake_say "#{ba.name}: imported #{importer.count}, assigned #{assign_count}"
|
2017-01-17 23:12:31 +01:00
|
|
|
end
|
|
|
|
end
|
2010-03-20 23:07:55 +01:00
|
|
|
end
|
2013-09-25 11:57:22 +02:00
|
|
|
|
|
|
|
# Helper
|
2013-09-30 10:57:54 +02:00
|
|
|
def rake_say(message)
|
2013-09-25 11:57:22 +02:00
|
|
|
puts message unless Rake.application.options.silent
|
|
|
|
end
|