Project

General

Profile

Feature #24277 » 04_add_remaining_time_to_version_5.1.2.patch

Radek Pesina, 2024-05-01 03:47

View differences:

app/models/version.rb
236 236
    fixed_issues.estimated_hours
237 237
  end
238 238

  
239
  # Returns the total remaining time for this version
240
  # (sum of leaves remaining_hours)
241
  def remaining_hours
242
    @remaining_hours ||= fixed_issues.sum(:remaining_hours).to_f
243
  end
244

  
239 245
  # Returns the total reported time for this version
240 246
  def spent_hours
241 247
    @spent_hours ||= TimeEntry.joins(:issue).where("#{Issue.table_name}.fixed_version_id = ?", id).sum(:hours).to_f
app/views/versions/show.html.erb
22 22
    <td class="total-hours"><%= link_to html_hours(l_hours(@version.visible_fixed_issues.estimated_hours)),
23 23
                                        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>
24 24
</tr>
25
<tr>
26
    <th><%= l(:field_remaining_hours) %></th>
27
    <td class="total-hours"><%= html_hours(l_hours(@version.remaining_hours)) %></td>
28
</tr>
25 29
<% if User.current.allowed_to_view_all_time_entries?(@project) %>
26 30
<tr>
27 31
    <th><%= l(:label_spent_time) %></th>
test/unit/version_test.rb
201 201
    assert_equal false, version.behind_schedule?
202 202
  end
203 203

  
204
  test "#estimated_hours should return 0 with no assigned issues" do
204
  test "#estimated_hours and remaining_hours should return 0 with no assigned issues" do
205 205
    version = Version.generate!
206 206
    assert_equal 0, version.estimated_hours
207
    assert_equal 0, version.remaining_hours
207 208
  end
208 209

  
209
  test "#estimated_hours should return 0 with no estimated hours" do
210
  test "#estimated_hours and remaining_hours should return 0 with no estimated hours" do
210 211
    version = Version.create!(:project_id => 1, :name => 'test')
211 212
    add_issue(version)
212 213
    assert_equal 0, version.estimated_hours
214
    assert_equal 0, version.remaining_hours
213 215
  end
214 216

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

  
222
  test "#estimated_hours should return the sum of leaves estimated hours" do
225
  test "#estimated_hours and remaining_hours should return the sum of leaves estimated hours and remaining hours" do
223 226
    version = Version.create!(:project_id => 1, :name => 'test')
224 227
    parent = add_issue(version)
225
    add_issue(version, :estimated_hours => 2.5, :parent_issue_id => parent.id)
226
    add_issue(version, :estimated_hours => 5, :parent_issue_id => parent.id)
228
    add_issue(version, :estimated_hours => 2.5, :remaining_hours => 1, :parent_issue_id => parent.id)
229
    add_issue(version, :estimated_hours => 5, :remaining_hours => 3, :parent_issue_id => parent.id)
227 230
    assert_equal 7.5, version.estimated_hours
231
    assert_equal 4, version.remaining_hours
228 232
  end
229 233

  
230 234
  test "should update all issue's fixed_version associations in case the hierarchy changed XXX" do
(14-14/14)