commit e5de30fbf383f662f9cfbed7f21745d817c68d5d Author: Marius BALTEANU Date: Tue Jul 4 02:21:38 2017 +0500 04 diff --git a/app/models/version.rb b/app/models/version.rb old mode 100644 new mode 100755 index b489389..0698a1c --- a/app/models/version.rb +++ b/app/models/version.rb @@ -108,6 +108,12 @@ class Version < ActiveRecord::Base @estimated_hours ||= fixed_issues.sum(:estimated_hours).to_f end + # Returns the total remaining time for this version + # (sum of leaves remaining_hours) + def remaining_hours + @remaining_hours ||= fixed_issues.sum(:remaining_hours).to_f + 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 old mode 100644 new mode 100755 index fc22a9f..fa96e77 --- a/app/views/versions/show.html.erb +++ b/app/views/versions/show.html.erb @@ -20,6 +20,10 @@ <%= link_to html_hours(l_hours(@version.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_remaining_hours) %> + <%= html_hours(l_hours(@version.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 old mode 100644 new mode 100755 index fe4993c..5163fb1 --- a/test/unit/version_test.rb +++ b/test/unit/version_test.rb @@ -193,30 +193,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 remaining_hours should return 0 with no assigned issues" do version = Version.generate! assert_equal 0, version.estimated_hours + assert_equal 0, version.remaining_hours end - test "#estimated_hours should return 0 with no estimated hours" do + test "#estimated_hours and 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.remaining_hours end - test "#estimated_hours should return return the sum of estimated hours" do + test "#estimated_hours and remaining_hours should return return the sum of estimated 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, :remaining_hours => 1) + add_issue(version, :estimated_hours => 5, :remaining_hours => 3) assert_equal 7.5, version.estimated_hours + assert_equal 4, version.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 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, :remaining_hours => 1, :parent_issue_id => parent.id) + add_issue(version, :estimated_hours => 5, :remaining_hours => 3, :parent_issue_id => parent.id) assert_equal 7.5, version.estimated_hours + assert_equal 4, version.remaining_hours end test "should update all issue's fixed_version associations in case the hierarchy changed XXX" do