issue-13400-trunk-r9702.diff

Toshi MARUYAMA, 2013-08-03 16:53

Download (6.7 KB)

View differences:

.hgignore
35 35
Gemfile.lock
36 36
Gemfile.local
37 37

  
38
*.orig
app/models/issue.rb
49 49
  acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]},
50 50
                            :author_key => :author_id
51 51

  
52
  DONE_RATIO_OPTIONS = %w(issue_field issue_status)
52
  DONE_RATIO_OPTIONS = %w(issue_field issue_status logged_time)
53 53

  
54 54
  attr_reader :current_journal
55 55

  
......
75 75
                            :conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"]
76 76

  
77 77
  before_create :default_assign
78
  before_save :close_duplicates, :update_done_ratio_from_issue_status
78
  before_save :close_duplicates, :update_done_ratio
79 79
  after_save {|issue| issue.send :after_project_change if !issue.id_changed? && issue.project_id_changed?} 
80 80
  after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal
81 81
  after_destroy :update_parent_attributes
......
355 355
  end
356 356

  
357 357
  def done_ratio
358
    if Issue.use_status_for_done_ratio? && status && status.default_done_ratio
358
    if use_status_for_done_ratio?
359 359
      status.default_done_ratio
360
    elsif use_time_for_done_ratio?
361
      if estimated_hours && estimated_hours.to_f > 0
362
        ratio = (total_spent_hours.to_f / estimated_hours.to_f) * 100
363
        [ratio, 100].min.to_i
364
      else
365
        0.0
366
      end
360 367
    else
361 368
      read_attribute(:done_ratio)
362 369
    end
......
365 372
  def self.use_status_for_done_ratio?
366 373
    Setting.issue_done_ratio == 'issue_status'
367 374
  end
375
  def use_status_for_done_ratio?
376
    Issue.use_status_for_done_ratio? && status && status.default_done_ratio
377
  end
378

  
379
  def self.use_time_for_done_ratio?
380
    Setting.issue_done_ratio == 'logged_time'
381
  end
382
  def use_time_for_done_ratio?
383
    Issue.use_time_for_done_ratio?
384
  end
368 385

  
369 386
  def self.use_field_for_done_ratio?
370 387
    Setting.issue_done_ratio == 'issue_field'
371 388
  end
389
  def use_field_for_done_ratio?
390
    !(use_status_for_done_ratio? || use_time_for_done_ratio?)
391
  end
372 392

  
373 393
  def validate_issue
374 394
    if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty?
......
417 437

  
418 438
  # Set the done_ratio using the status if that setting is set.  This will keep the done_ratios
419 439
  # even if the user turns off the setting later
420
  def update_done_ratio_from_issue_status
421
    if Issue.use_status_for_done_ratio? && status && status.default_done_ratio
422
      self.done_ratio = status.default_done_ratio
440
  def update_done_ratio
441
    unless use_field_for_done_ratio?
442
      self.done_ratio = self.done_ratio
423 443
    end
424 444
  end
425 445

  
446
  def update_done_ratio!
447
    self.init_journal(User.current, "")
448
    self.update_done_ratio
449
    self.save
450
  end
451

  
426 452
  def init_journal(user, notes = "")
427 453
    @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes)
428 454
    if new_record?
......
904 930
      end
905 931

  
906 932
      # done ratio = weighted average ratio of leaves
907
      unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio
933
      if p.use_field_for_done_ratio
908 934
        leaves_count = p.leaves.count
909 935
        if leaves_count > 0
910 936
          average = p.leaves.average(:estimated_hours).to_f
app/models/time_entry.rb
40 40
  validates_numericality_of :hours, :allow_nil => true, :message => :invalid
41 41
  validates_length_of :comments, :maximum => 255, :allow_nil => true
42 42
  before_validation :set_project_if_nil
43
  after_save :update_done_ratio
44
  after_destroy :update_done_ratio
43 45
  validate :validate_time_entry
44 46

  
45 47
  scope :visible, lambda {|*args| {
......
88 90
    errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project)
89 91
  end
90 92

  
93
  def update_done_ratio
94
    if issue && Issue.use_time_for_done_ratio?
95
      issue.update_done_ratio!
96
    end
97
  end
98

  
91 99
  def hours=(h)
92 100
    write_attribute :hours, (h.is_a?(String) ? (h.to_hours || h) : h)
93 101
  end
config/locales/de.yml
369 369
  setting_start_of_week: Wochenanfang
370 370
  setting_rest_api_enabled: REST-Schnittstelle aktivieren
371 371
  setting_cache_formatted_text: Formatierten Text im Cache speichern
372
  setting_issue_done_ratio_logged_time: Gesch├Ątzter und gebuchter Zeit
372 373

  
373 374
  permission_add_project: Projekt erstellen
374 375
  permission_add_subprojects: Unterprojekte erstellen
config/locales/en.yml
374 374
  setting_issue_done_ratio: Calculate the issue done ratio with
375 375
  setting_issue_done_ratio_issue_field: Use the issue field
376 376
  setting_issue_done_ratio_issue_status: Use the issue status
377
  setting_issue_done_ratio_logged_time: Use the logged and estimated time
377 378
  setting_start_of_week: Start calendars on
378 379
  setting_rest_api_enabled: Enable REST web service
379 380
  setting_cache_formatted_text: Cache formatted text
test/unit/issue_test.rb
1104 1104
    end
1105 1105
  end
1106 1106

  
1107
  context "#update_done_ratio_from_issue_status" do
1107
  context "#update_done_ratio" do
1108 1108
    setup do
1109 1109
      @issue = Issue.find(1)
1110 1110
      @issue_status = IssueStatus.find(1)
......
1120 1120
      end
1121 1121

  
1122 1122
      should "not change the issue" do
1123
        @issue.update_done_ratio_from_issue_status
1124
        @issue2.update_done_ratio_from_issue_status
1123
        @issue.update_done_ratio
1124
        @issue2.update_done_ratio
1125 1125

  
1126 1126
        assert_equal 0, @issue.read_attribute(:done_ratio)
1127 1127
        assert_equal 30, @issue2.read_attribute(:done_ratio)
......
1134 1134
      end
1135 1135

  
1136 1136
      should "change the issue's done ratio" do
1137
        @issue.update_done_ratio_from_issue_status
1138
        @issue2.update_done_ratio_from_issue_status
1137
        @issue.update_done_ratio
1138
        @issue2.update_done_ratio
1139 1139

  
1140 1140
        assert_equal 50, @issue.read_attribute(:done_ratio)
1141 1141
        assert_equal 0, @issue2.read_attribute(:done_ratio)