Outlined new concept for multiple periodically recurring tasks (#3).
This commit is contained in:
parent
1822b330d1
commit
1cdb9e8501
7 changed files with 73 additions and 8 deletions
23
app/models/periodic_task_group.rb
Normal file
23
app/models/periodic_task_group.rb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
class PeriodicTaskGroup < ActiveRecord::Base
|
||||
has_many :tasks, :inverse_of => :periodic_task_group, :dependent => :destroy
|
||||
|
||||
PeriodDays = 7
|
||||
|
||||
def has_next_task?
|
||||
return false if self.tasks.empty?
|
||||
return false if self.tasks.first.due_date.nil?
|
||||
return true
|
||||
end
|
||||
|
||||
def create_next_task
|
||||
template_task = self.tasks.first
|
||||
self.next_task_date ||= template_task.due_date + PeriodDays
|
||||
|
||||
next_task = template_task.dup
|
||||
next_task.due_date = self.next_task_date
|
||||
next_task.save
|
||||
|
||||
self.next_task_date += PeriodDays
|
||||
self.save
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue