From 2d296d6e7ec8d4228b0e86f2ad14c6905d8c527d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marius=20B=C4=82LTEANU?= Date: Thu, 2 May 2024 19:14:46 +0300 Subject: [PATCH 2/2] Adds estimated remaining time to version page (#37862, #1671). diff --git a/app/models/version.rb b/app/models/version.rb index 17e1128e4..6129371f7 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -24,6 +24,12 @@ module FixedIssuesExtension @estimated_hours ||= sum(:estimated_hours).to_f end + # Returns the total estimated remaining time for this version + # (sum of leaves remaining_estimated_hours) + def estimated_remaining_hours + @estimated_remaining_hours ||= sum(IssueQuery::ESTIMATED_REMAINING_HOURS_SQL).to_f + end + # Returns the total amount of open issues for this version. def open_count load_counts @@ -236,6 +242,12 @@ class Version < ApplicationRecord fixed_issues.estimated_hours end + # Returns the total estimated remaining time for this version + # (sum of leaves estimated_remaining_hours) + def estimated_remaining_hours + @remaining_hours ||= fixed_issues.estimated_remaining_hours + end + # Returns the total reported time for this version def spent_hours @spent_hours ||= TimeEntry.joins(:issue).where("#{Issue.table_name}.fixed_version_id = ?", id).sum(:hours).to_f diff --git a/app/views/versions/show.html.erb b/app/views/versions/show.html.erb index e17571075..88eb4b841 100644 --- a/app/views/versions/show.html.erb +++ b/app/views/versions/show.html.erb @@ -22,6 +22,13 @@ <%= link_to html_hours(l_hours(@version.visible_fixed_issues.estimated_hours)), project_issues_path(@version.project, :set_filter => 1, :status_id => '*', :fixed_version_id => @version.id, :c => [:tracker, :status, :subject, :estimated_hours], :t => [:estimated_hours]) %> + + <%= l(:field_estimated_remaining_hours) %> + + <%= link_to html_hours(l_hours(@version.visible_fixed_issues.estimated_remaining_hours)), + project_issues_path(@version.project, :set_filter => 1, :status_id => '*', :fixed_version_id => @version.id, :c => [:tracker, :status, :subject, :estimated_remaining_hours], :t => [:estimated_remaining_hours]) %> + + <% if User.current.allowed_to_view_all_time_entries?(@project) %> <%= l(:label_spent_time) %> diff --git a/test/unit/version_test.rb b/test/unit/version_test.rb index 45c5bed37..124a874f6 100644 --- a/test/unit/version_test.rb +++ b/test/unit/version_test.rb @@ -201,30 +201,34 @@ class VersionTest < ActiveSupport::TestCase assert_equal false, version.behind_schedule? end - test "#estimated_hours should return 0 with no assigned issues" do + test "#estimated_hours and estimated_remaining_hours should return 0 with no assigned issues" do version = Version.generate! assert_equal 0, version.estimated_hours + assert_equal 0, version.estimated_remaining_hours end - test "#estimated_hours should return 0 with no estimated hours" do + test "#estimated_hours and estimated_remaining_hours should return 0 with no estimated hours" do version = Version.create!(:project_id => 1, :name => 'test') add_issue(version) assert_equal 0, version.estimated_hours + assert_equal 0, version.estimated_remaining_hours end - test "#estimated_hours should return return the sum of estimated hours" do + test "#estimated_hours and estimated_remaining_hours should return the sum of estimated hours and estimated remaining hours" do version = Version.create!(:project_id => 1, :name => 'test') - add_issue(version, :estimated_hours => 2.5) - add_issue(version, :estimated_hours => 5) + add_issue(version, :estimated_hours => 2.5, :done_ratio => 90) + add_issue(version, :estimated_hours => 5, :done_ratio => 50) assert_equal 7.5, version.estimated_hours + assert_equal 2.75, version.estimated_remaining_hours end - test "#estimated_hours should return the sum of leaves estimated hours" do + test "#estimated_hours and remaining_hours should return the sum of leaves estimated hours and estimated remaining hours" do version = Version.create!(:project_id => 1, :name => 'test') parent = add_issue(version) - add_issue(version, :estimated_hours => 2.5, :parent_issue_id => parent.id) - add_issue(version, :estimated_hours => 5, :parent_issue_id => parent.id) + add_issue(version, :estimated_hours => 2.5, :done_ratio => 90, :parent_issue_id => parent.id) + add_issue(version, :estimated_hours => 5, :done_ratio => 50, :parent_issue_id => parent.id) assert_equal 7.5, version.estimated_hours + assert_equal 2.75, version.estimated_remaining_hours end test "should update all issue's fixed_version associations in case the hierarchy changed XXX" do -- 2.39.3 (Apple Git-146)