Create next tasks directly after creating a periodic task
This commit is contained in:
parent
6015d16cab
commit
9ae7c05a89
3 changed files with 17 additions and 7 deletions
|
@ -22,6 +22,7 @@ class TasksController < ApplicationController
|
|||
@task.periodic_task_group = PeriodicTaskGroup.new
|
||||
end
|
||||
if @task.save
|
||||
@task.periodic_task_group.create_tasks_for_upfront_days if params[:periodic]
|
||||
redirect_to tasks_url, :notice => I18n.t('tasks.create.notice')
|
||||
else
|
||||
render :template => "tasks/new"
|
||||
|
|
|
@ -19,6 +19,20 @@ class PeriodicTaskGroup < ActiveRecord::Base
|
|||
self.save
|
||||
end
|
||||
|
||||
def create_tasks_until(create_until)
|
||||
if has_next_task?
|
||||
while next_task_date.nil? || next_task_date < create_until
|
||||
create_next_task
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def create_tasks_for_upfront_days
|
||||
create_until = Date.today + FoodsoftConfig[:tasks_upfront_days].to_i + 1
|
||||
create_tasks_until create_until
|
||||
create_until
|
||||
end
|
||||
|
||||
def exclude_tasks_before(task)
|
||||
tasks.where("due_date < '#{task.due_date}'").each do |t|
|
||||
t.update_attribute(:periodic_task_group, nil)
|
||||
|
|
|
@ -39,13 +39,8 @@ namespace :foodsoft do
|
|||
desc "Create upcoming periodic tasks"
|
||||
task :create_upcoming_periodic_tasks => :environment do
|
||||
for tg in PeriodicTaskGroup.all
|
||||
if tg.has_next_task?
|
||||
create_until = Date.today + FoodsoftConfig[:tasks_upfront_days].to_i + 1
|
||||
rake_say "creating until #{create_until}"
|
||||
while tg.next_task_date.nil? || tg.next_task_date < create_until
|
||||
tg.create_next_task
|
||||
end
|
||||
end
|
||||
created_until tg.create_tasks_for_upfront_days
|
||||
rake_say "created until #{created_until}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue