Project

General

Profile

Feature #24277 » 03_calculate_done_ratio_using_time_3.4.1.patch

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

View differences:

app/models/issue.rb
52 52
  acts_as_activity_provider :scope => preload(:project, :author, :tracker, :status),
53 53
                            :author_key => :author_id
54 54

  
55
  DONE_RATIO_OPTIONS = %w(issue_field issue_status)
55
  DONE_RATIO_OPTIONS = %w(issue_field issue_status issue_time)
56 56

  
57 57
  attr_accessor :deleted_attachment_ids
58 58
  attr_reader :current_journal
......
698 698
  def done_ratio
699 699
    if Issue.use_status_for_done_ratio? && status && status.default_done_ratio
700 700
      status.default_done_ratio
701
    elsif Issue.use_time_for_done_ratio?
702
      if done_ratio_derived?
703
        calculate_done_ratio_from_time(total_estimated_hours, total_remaining_hours)
704
      else
705
        calculate_done_ratio_from_time(estimated_hours, remaining_hours)
706
      end
701 707
    else
702 708
      read_attribute(:done_ratio)
703 709
    end
......
711 717
    Setting.issue_done_ratio == 'issue_field'
712 718
  end
713 719

  
720
  def self.use_time_for_done_ratio?
721
    Setting.issue_done_ratio == 'issue_time'
722
  end
723

  
714 724
  def validate_issue
715 725
    if due_date && start_date && (start_date_changed? || due_date_changed?) && due_date < start_date
716 726
      errors.add :due_date, :greater_than_start_date
......
1902 1912
      self.done_ratio ||= 0
1903 1913
    end
1904 1914
  end
1915

  
1916
  def calculate_done_ratio_from_time(estimated, remaining)
1917
    if remaining.to_f == 0
1918
      100
1919
    elsif remaining.to_f > 0
1920
      ratio = (estimated.to_f - remaining.to_f) / estimated.to_f * 100
1921
      [ratio, 0].max.to_i
1922
    else
1923
      0.0
1924
    end
1925
  end
1905 1926
end
config/locales/en.yml
435 435
  setting_issue_done_ratio: Calculate the issue done ratio with
436 436
  setting_issue_done_ratio_issue_field: Use the issue field
437 437
  setting_issue_done_ratio_issue_status: Use the issue status
438
  setting_issue_done_ratio_issue_time: Use the issue remaining and estimated time
438 439
  setting_start_of_week: Start calendars on
439 440
  setting_rest_api_enabled: Enable REST web service
440 441
  setting_cache_formatted_text: Cache formatted text
test/unit/issue_subtasking_test.rb
238 238
    end
239 239
  end
240 240

  
241
  def test_done_ratio_should_be_calculated_from_total_estimated_and_total_remaining_time
242
    with_settings :parent_issue_done_ratio => 'derived', :issue_done_ratio => 'issue_time' do
243
      parent = Issue.generate!
244
      parent.generate_child!(:estimated_hours => 40, :remaining_hours => 20)
245
      parent.generate_child!(:estimated_hours => 40, :remaining_hours => 10)
246
      parent.generate_child!(:estimated_hours => 20, :remaining_hours => 20)
247
      parent.generate_child!(:estimated_hours => 0, :remaining_hours => 0)
248

  
249
      assert_equal 50, parent.reload.done_ratio
250
    end
251
  end
252

  
241 253
  def test_done_ratio_of_parent_should_reflect_children
242 254
    root = Issue.generate!
243 255
    child1 = root.generate_child!
test/unit/issue_test.rb
2656 2656
    end
2657 2657
  end
2658 2658

  
2659
  def test_done_ratio_should_be_calculated_from_estimated_and_remaining_time
2660
    @issue = Issue.find(1)
2661
    @issue.update_attribute(:estimated_hours, 50)
2662
    @issue.update_attribute(:remaining_hours, 25)
2663

  
2664
    @issue2 = Issue.find(2)
2665
    @issue2.update_attribute(:estimated_hours, 50)
2666
    @issue2.update_attribute(:remaining_hours, 50)
2667

  
2668
    @issue3 = Issue.find(3)
2669
    @issue3.update_attribute(:estimated_hours, 50)
2670
    @issue3.update_attribute(:remaining_hours, 0)
2671

  
2672
    with_settings :issue_done_ratio => 'issue_time' do
2673
      assert_equal 50, @issue.done_ratio
2674
      assert_equal 0, @issue2.done_ratio
2675
      assert_equal 100, @issue3.done_ratio
2676
    end
2677
  end
2678

  
2659 2679
  test "#by_tracker" do
2660 2680
    User.current = User.anonymous
2661 2681
    groups = Issue.by_tracker(Project.find(1))
(8-8/14)