Project

General

Profile

Feature #24277 » 04_add_remaining_time_to_version_3.4.1.patch

Marius BĂLTEANU, 2017-07-10 19:50

View differences:

app/models/version.rb
108 108
    @estimated_hours ||= fixed_issues.sum(:estimated_hours).to_f
109 109
  end
110 110

  
111
  # Returns the total remaining time for this version
112
  # (sum of leaves remaining_hours)
113
  def remaining_hours
114
    @remaining_hours ||= fixed_issues.sum(:remaining_hours).to_f
115
  end
116

  
111 117
  # Returns the total reported time for this version
112 118
  def spent_hours
113 119
    @spent_hours ||= TimeEntry.joins(:issue).where("#{Issue.table_name}.fixed_version_id = ?", id).sum(:hours).to_f
app/views/versions/show.html.erb
20 20
    <td class="total-hours"><%= link_to html_hours(l_hours(@version.estimated_hours)),
21 21
                                        project_issues_path(@version.project, :set_filter => 1, :status_id => '*', :fixed_version_id => @version.id, :c => [:tracker, :status, :subject, :estimated_hours], :t => [:estimated_hours]) %></td>
22 22
</tr>
23
<tr>
24
    <th><%= l(:field_remaining_hours) %></th>
25
    <td class="total-hours"><%= html_hours(l_hours(@version.remaining_hours)) %></td>
26
</tr>
23 27
<% if User.current.allowed_to_view_all_time_entries?(@project) %>
24 28
<tr>
25 29
    <th><%= l(:label_spent_time) %></th>
test/unit/version_test.rb
193 193
    assert_equal false, version.behind_schedule?
194 194
  end
195 195

  
196
  test "#estimated_hours should return 0 with no assigned issues" do
196
  test "#estimated_hours and remaining_hours should return 0 with no assigned issues" do
197 197
    version = Version.generate!
198 198
    assert_equal 0, version.estimated_hours
199
    assert_equal 0, version.remaining_hours
199 200
  end
200 201

  
201
  test "#estimated_hours should return 0 with no estimated hours" do
202
  test "#estimated_hours and remaining_hours should return 0 with no estimated hours" do
202 203
    version = Version.create!(:project_id => 1, :name => 'test')
203 204
    add_issue(version)
204 205
    assert_equal 0, version.estimated_hours
206
    assert_equal 0, version.remaining_hours
205 207
  end
206 208

  
207
  test "#estimated_hours should return return the sum of estimated hours" do
209
  test "#estimated_hours and remaining_hours should return return the sum of estimated hours" do
208 210
    version = Version.create!(:project_id => 1, :name => 'test')
209
    add_issue(version, :estimated_hours => 2.5)
210
    add_issue(version, :estimated_hours => 5)
211
    add_issue(version, :estimated_hours => 2.5, :remaining_hours => 1)
212
    add_issue(version, :estimated_hours => 5, :remaining_hours => 3)
211 213
    assert_equal 7.5, version.estimated_hours
214
    assert_equal 4, version.remaining_hours
212 215
  end
213 216

  
214
  test "#estimated_hours should return the sum of leaves estimated hours" do
217
  test "#estimated_hours and remaining_hours should return the sum of leaves estimated hours and remaining hours" do
215 218
    version = Version.create!(:project_id => 1, :name => 'test')
216 219
    parent = add_issue(version)
217
    add_issue(version, :estimated_hours => 2.5, :parent_issue_id => parent.id)
218
    add_issue(version, :estimated_hours => 5, :parent_issue_id => parent.id)
220
    add_issue(version, :estimated_hours => 2.5, :remaining_hours => 1, :parent_issue_id => parent.id)
221
    add_issue(version, :estimated_hours => 5, :remaining_hours => 3, :parent_issue_id => parent.id)
219 222
    assert_equal 7.5, version.estimated_hours
223
    assert_equal 4, version.remaining_hours
220 224
  end
221 225

  
222 226
  test "should update all issue's fixed_version associations in case the hierarchy changed XXX" do
(10-10/10)