Class: WorkEffort

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ErpTechSvcs::Utils::DefaultNestedSetMethods
Defined in:
app/models/work_effort.rb

Direct Known Subclasses

ProjectEffort, SupportEffort

Instance Method Summary collapse

Instance Method Details

#complete_work_effortObject



122
123
124
125
126
127
# File 'app/models/work_effort.rb', line 122

def complete_work_effort
  self.finished_at = Time.now
  self.actual_completion_time = time_diff_in_minutes(self.finished_at.to_time, self.started_at.to_time)
  self.save
  self.parent.start_effort unless self.parent.nil?
end

#completed?Boolean

return true if this effort has been completed, false otherwise

Returns:

  • (Boolean)


28
29
30
# File 'app/models/work_effort.rb', line 28

def completed?
  finished_at.nil? ? false : true
end

#send_to_next_statusObject

completes current status start next status if not last status starts parent status if parent exists



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/models/work_effort.rb', line 76

def send_to_next_status
  current_status = get_current_status

  unless current_status.nil?
    next_status_type = current_status.work_effort_status_type.next_status_type

    if next_status_type.nil?
      complete_work_effort
    else
      new_work_effort_status = WorkEffortStatus.new
      new_work_effort_status.started_at = DateTime.now
      new_work_effort_status.work_effort_status_type = next_status_type
      new_work_effort_status.work_effort = self
      new_work_effort_status.save
    end

    current_status.finished_at = DateTime.now
    current_status.save
  else
    raise 'Effort Has Not Started' if current_status.nil?
  end
end

#send_to_previous_statusObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'app/models/work_effort.rb', line 99

def send_to_previous_status
  current_status = get_current_status

  unless current_status.nil?
    previous_status_type = current_status.work_effort_status_type.previous_status_type

    if previous_status_type.nil?
      raise 'Current status is initial status' if current_status.nil?
    else
      new_work_effort_status = WorkEffortStatus.new
      new_work_effort_status.started_at = DateTime.now
      new_work_effort_status.work_effort_status_type = previous_status_type
      new_work_effort_status.work_effort = self
      new_work_effort_status.save
    end

    current_status.finished_at = DateTime.now
    current_status.save
  else
    raise 'Effort Has Not Started' if current_status.nil?
  end
end

#send_to_status(status_type, complete_effort = false, complete_status = false) ⇒ Object

completes current status if current status is in progress start status passed in if status passed in is last status, starts parent status if status exists



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/models/work_effort.rb', line 55

def send_to_status(status_type, complete_effort=false, complete_status=false)
  current_status = get_current_status
  
  unless current_status.nil?
    new_work_effort_status = WorkEffortStatus.new
    new_work_effort_status.started_at = DateTime.now
    new_work_effort_status.finished_at = new_work_effort_status.started_at if complete_status
    new_work_effort_status.work_effort_status_type = status_type
    new_work_effort_status.work_effort = self
    new_work_effort_status.save
    current_status.finished_at = DateTime.now
    current_status.save
    complete_work_effort if complete_effort
  else
    raise 'Effort Has Not Started'
  end
end

#start(status_type) ⇒ Object

start initial work_status



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/work_effort.rb', line 33

def start(status_type)
  effort = self
  unless self.descendants.flatten!.nil?
    children = self.descendants.flatten
    effort = children.last
  end

  current_status = effort.get_current_status

  if current_status.nil?
    work_effort_status = WorkEffortStatus.create(:started_at => DateTime.now, :work_effort_status_type => status_type)
    effort.work_effort_statuses << work_effort_status
    effort.started_at = DateTime.now
    effort.save
  else
    raise 'Effort Already Started'
  end
end

#started?Boolean

return true if this effort has been started, false otherwise

Returns:

  • (Boolean)


23
24
25
# File 'app/models/work_effort.rb', line 23

def started?
  get_current_status.nil? ? false : true
end

#statusObject

get current status



17
18
19
20
# File 'app/models/work_effort.rb', line 17

def status
  work_effort_status = self.descendants.flatten!.nil? ? self.get_current_status : self.descendants.flatten!.last.get_current_status
  work_effort_status.work_effort_status_type.description
end