commit 417fd68b217368ae73ae12fc06042174227f0b77 Author: Holger Just Date: Mon Mar 4 18:51:15 2013 +0100 Calculate %done on issues based on estimated and logged time #108448 diff --git a/app/models/issue.rb b/app/models/issue.rb index 9c71538..7bcfdd4 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -49,7 +49,7 @@ class Issue < ActiveRecord::Base acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]}, :author_key => :author_id - DONE_RATIO_OPTIONS = %w(issue_field issue_status) + DONE_RATIO_OPTIONS = %w(issue_field issue_status logged_time) attr_reader :current_journal @@ -74,7 +74,7 @@ class Issue < ActiveRecord::Base :conditions => ["#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"] before_create :default_assign - before_save :close_duplicates, :update_done_ratio_from_issue_status + before_save :close_duplicates, :update_done_ratio after_save {|issue| issue.send :after_project_change if !issue.id_changed? && issue.project_id_changed?} after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal after_destroy :update_parent_attributes @@ -376,8 +376,15 @@ class Issue < ActiveRecord::Base end def done_ratio - if Issue.use_status_for_done_ratio? && status && status.default_done_ratio + if use_status_for_done_ratio? status.default_done_ratio + elsif use_time_for_done_ratio? + if estimated_hours && estimated_hours.to_f > 0 + ratio = (total_spent_hours.to_f / estimated_hours.to_f) * 100 + [ratio, 100].min.to_i + else + 0.0 + end else read_attribute(:done_ratio) end @@ -386,10 +393,23 @@ class Issue < ActiveRecord::Base def self.use_status_for_done_ratio? Setting.issue_done_ratio == 'issue_status' end + def use_status_for_done_ratio? + Issue.use_status_for_done_ratio? && status && status.default_done_ratio + end + + def self.use_time_for_done_ratio? + Setting.issue_done_ratio == 'logged_time' + end + def use_time_for_done_ratio? + Issue.use_time_for_done_ratio? + end def self.use_field_for_done_ratio? Setting.issue_done_ratio == 'issue_field' end + def use_field_for_done_ratio? + !(use_status_for_done_ratio? || use_time_for_done_ratio?) + end def validate_issue if self.due_date.nil? && @attributes['due_date'] && !@attributes['due_date'].empty? @@ -438,12 +458,18 @@ class Issue < ActiveRecord::Base # Set the done_ratio using the status if that setting is set. This will keep the done_ratios # even if the user turns off the setting later - def update_done_ratio_from_issue_status - if Issue.use_status_for_done_ratio? && status && status.default_done_ratio - self.done_ratio = status.default_done_ratio + def update_done_ratio + unless use_field_for_done_ratio? + self.done_ratio = self.done_ratio end end + def update_done_ratio! + self.init_journal(User.current, "") + self.update_done_ratio + self.save + end + def init_journal(user, notes = "") @current_journal ||= Journal.new(:journalized => self, :user => user, :notes => notes) if new_record? @@ -955,7 +981,7 @@ class Issue < ActiveRecord::Base end # done ratio = weighted average ratio of leaves - unless Issue.use_status_for_done_ratio? && p.status && p.status.default_done_ratio + if p.use_field_for_done_ratio leaves_count = p.leaves.count if leaves_count > 0 average = p.leaves.average(:estimated_hours).to_f diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb index d7c6996..860e90f 100644 --- a/app/models/time_entry.rb +++ b/app/models/time_entry.rb @@ -40,6 +40,8 @@ class TimeEntry < ActiveRecord::Base validates_numericality_of :hours, :allow_nil => true, :message => :invalid validates_length_of :comments, :maximum => 255, :allow_nil => true before_validation :set_project_if_nil + after_save :update_done_ratio + after_destroy :update_done_ratio validate :validate_time_entry named_scope :visible, lambda {|*args| { @@ -88,6 +90,12 @@ class TimeEntry < ActiveRecord::Base errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project) end + def update_done_ratio + if issue && Issue.use_time_for_done_ratio? + issue.update_done_ratio! + end + end + def hours=(h) write_attribute :hours, (h.is_a?(String) ? (h.to_hours || h) : h) end diff --git a/config/locales/ar.yml b/config/locales/ar.yml index c3f7c7d..ee605cc 100644 --- a/config/locales/ar.yml +++ b/config/locales/ar.yml @@ -1068,3 +1068,4 @@ ar: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/bg.yml b/config/locales/bg.yml index e8bd7a4..37cc361 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -1065,3 +1065,4 @@ bg: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/bs.yml b/config/locales/bs.yml index 3afd0a3..64595cc 100644 --- a/config/locales/bs.yml +++ b/config/locales/bs.yml @@ -1082,3 +1082,4 @@ bs: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 65c821d..e867b3a 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -1070,3 +1070,4 @@ ca: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/cs.yml b/config/locales/cs.yml index a93cdda..ef78075 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -1071,3 +1071,4 @@ cs: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/da.yml b/config/locales/da.yml index 2a9aec7..c3c7657 100644 --- a/config/locales/da.yml +++ b/config/locales/da.yml @@ -1085,3 +1085,4 @@ da: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/de.yml b/config/locales/de.yml index f1e8172..cb2e4a8 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1082,3 +1082,4 @@ de: label_required: Required label_attribute_of_project: Project's %{name} label_status_transitions: Status transitions + setting_issue_done_ratio_logged_time: Geschätzter und gebuchter Zeit diff --git a/config/locales/el.yml b/config/locales/el.yml index d0dc6d2..71c5423 100644 --- a/config/locales/el.yml +++ b/config/locales/el.yml @@ -1068,3 +1068,4 @@ el: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/en-GB.yml b/config/locales/en-GB.yml index 2dd3bd1..41346aa 100644 --- a/config/locales/en-GB.yml +++ b/config/locales/en-GB.yml @@ -1070,3 +1070,4 @@ en-GB: label_attribute_of_project: Project's %{name} label_status_transitions: Status transitions button_mail_link: Send by e-mail + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/en.yml b/config/locales/en.yml index 876ab21..a799eda 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -385,6 +385,7 @@ en: setting_issue_done_ratio: Calculate the issue done ratio with setting_issue_done_ratio_issue_field: Use the issue field setting_issue_done_ratio_issue_status: Use the issue status + setting_issue_done_ratio_logged_time: Use the logged and estimated time setting_start_of_week: Start calendars on setting_rest_api_enabled: Enable REST web service setting_cache_formatted_text: Cache formatted text diff --git a/config/locales/es.yml b/config/locales/es.yml index 67d9047..b1a63a6 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -1105,3 +1105,4 @@ es: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/et.yml b/config/locales/et.yml index 403caab..c787dff 100644 --- a/config/locales/et.yml +++ b/config/locales/et.yml @@ -1084,3 +1084,4 @@ et: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/eu.yml b/config/locales/eu.yml index 4c7f3e5..816611f 100644 --- a/config/locales/eu.yml +++ b/config/locales/eu.yml @@ -1071,3 +1071,4 @@ eu: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/fa.yml b/config/locales/fa.yml index be9dd6c..e90bd61 100644 --- a/config/locales/fa.yml +++ b/config/locales/fa.yml @@ -1070,3 +1070,4 @@ fa: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/fi.yml b/config/locales/fi.yml index 8749194..2fb121a 100644 --- a/config/locales/fi.yml +++ b/config/locales/fi.yml @@ -1089,3 +1089,4 @@ fi: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/fr.yml b/config/locales/fr.yml index c2d4cb4..426dc1c 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -1081,3 +1081,4 @@ fr: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/gl.yml b/config/locales/gl.yml index 8f9a859..329a4b2 100644 --- a/config/locales/gl.yml +++ b/config/locales/gl.yml @@ -1079,3 +1079,4 @@ gl: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/he.yml b/config/locales/he.yml index 622eede..fdb6c48 100644 --- a/config/locales/he.yml +++ b/config/locales/he.yml @@ -1073,3 +1073,4 @@ he: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/hr.yml b/config/locales/hr.yml index 701e701..058d398 100644 --- a/config/locales/hr.yml +++ b/config/locales/hr.yml @@ -1071,3 +1071,4 @@ hr: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/hu.yml b/config/locales/hu.yml index 9e18458..08a0a53 100644 --- a/config/locales/hu.yml +++ b/config/locales/hu.yml @@ -1087,3 +1087,4 @@ field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/id.yml b/config/locales/id.yml index 3a6aff4..38c4970 100644 --- a/config/locales/id.yml +++ b/config/locales/id.yml @@ -1074,3 +1074,4 @@ id: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/it.yml b/config/locales/it.yml index aaaa0b9..589dc32 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -1069,3 +1069,4 @@ it: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/ja.yml b/config/locales/ja.yml index dd1e0e3..331901f 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -1098,3 +1098,4 @@ ja: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/ko.yml b/config/locales/ko.yml index 4dfcb30..8cd8ade 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -1118,3 +1118,4 @@ ko: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/lt.yml b/config/locales/lt.yml index 1bdf5dc..d269320 100644 --- a/config/locales/lt.yml +++ b/config/locales/lt.yml @@ -1128,3 +1128,4 @@ lt: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/lv.yml b/config/locales/lv.yml index fb001e5..3feee30 100644 --- a/config/locales/lv.yml +++ b/config/locales/lv.yml @@ -1062,3 +1062,4 @@ lv: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/mk.yml b/config/locales/mk.yml index 8eabbfa..d511ed6 100644 --- a/config/locales/mk.yml +++ b/config/locales/mk.yml @@ -1068,3 +1068,4 @@ mk: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/mn.yml b/config/locales/mn.yml index 64dd1eb..2527b72 100644 --- a/config/locales/mn.yml +++ b/config/locales/mn.yml @@ -1068,3 +1068,4 @@ mn: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/nl.yml b/config/locales/nl.yml index f3d1495..ce372eb 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -1053,3 +1053,4 @@ nl: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/no.yml b/config/locales/no.yml index c22198b..8f08ed2 100644 --- a/config/locales/no.yml +++ b/config/locales/no.yml @@ -1059,3 +1059,4 @@ field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 6e4faa3..dfc93cc 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -1085,3 +1085,4 @@ pl: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 2f34b63..da13828 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -1090,3 +1090,4 @@ pt-BR: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 98bee1d..c93a52b 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -1073,3 +1073,4 @@ pt: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/ro.yml b/config/locales/ro.yml index 35a2617..e8d43bd 100644 --- a/config/locales/ro.yml +++ b/config/locales/ro.yml @@ -1065,3 +1065,4 @@ ro: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 3304910..fcdb3fd 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -1181,3 +1181,4 @@ ru: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/sk.yml b/config/locales/sk.yml index 6d90ecf..6a5414f 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -1068,3 +1068,4 @@ sk: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/sl.yml b/config/locales/sl.yml index 98e94ba..9a159bc 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -1068,3 +1068,4 @@ sl: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/sq.yml b/config/locales/sq.yml index 893c2bf..b37363b 100644 --- a/config/locales/sq.yml +++ b/config/locales/sq.yml @@ -1072,3 +1072,4 @@ sq: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/sr-YU.yml b/config/locales/sr-YU.yml index 586b1ab..c37b1e8 100644 --- a/config/locales/sr-YU.yml +++ b/config/locales/sr-YU.yml @@ -1068,3 +1068,4 @@ sr-YU: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/sr.yml b/config/locales/sr.yml index d575d71..b650424 100644 --- a/config/locales/sr.yml +++ b/config/locales/sr.yml @@ -1069,3 +1069,4 @@ sr: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/sv.yml b/config/locales/sv.yml index 3af0acb..fb3f6e8 100644 --- a/config/locales/sv.yml +++ b/config/locales/sv.yml @@ -1106,3 +1106,4 @@ sv: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/th.yml b/config/locales/th.yml index 2fe9e02..6a8adbe 100644 --- a/config/locales/th.yml +++ b/config/locales/th.yml @@ -1065,3 +1065,4 @@ th: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/tr.yml b/config/locales/tr.yml index 3090557..16480b7 100644 --- a/config/locales/tr.yml +++ b/config/locales/tr.yml @@ -1087,3 +1087,4 @@ tr: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/uk.yml b/config/locales/uk.yml index 5014799..caaa2b8 100644 --- a/config/locales/uk.yml +++ b/config/locales/uk.yml @@ -1063,3 +1063,4 @@ uk: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/vi.yml b/config/locales/vi.yml index 923128f..17b11a5 100644 --- a/config/locales/vi.yml +++ b/config/locales/vi.yml @@ -1119,3 +1119,4 @@ vi: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index d3e09f7..df3993b 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -1148,3 +1148,4 @@ field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 8804682..ee7c0b0 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -1070,3 +1070,4 @@ zh: field_author_role: Author's role button_mail_link: Send by e-mail label_add_to_all_workflows: Add to all workflows + setting_issue_done_ratio_logged_time: Use the logged and estimated time diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 3b886f1..b230f1b 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -1127,7 +1127,7 @@ class IssueTest < ActiveSupport::TestCase end end - context "#update_done_ratio_from_issue_status" do + context "#update_done_ratio" do setup do @issue = Issue.find(1) @issue_status = IssueStatus.find(1) @@ -1143,8 +1143,8 @@ class IssueTest < ActiveSupport::TestCase end should "not change the issue" do - @issue.update_done_ratio_from_issue_status - @issue2.update_done_ratio_from_issue_status + @issue.update_done_ratio + @issue2.update_done_ratio assert_equal 0, @issue.read_attribute(:done_ratio) assert_equal 30, @issue2.read_attribute(:done_ratio) @@ -1157,8 +1157,8 @@ class IssueTest < ActiveSupport::TestCase end should "change the issue's done ratio" do - @issue.update_done_ratio_from_issue_status - @issue2.update_done_ratio_from_issue_status + @issue.update_done_ratio + @issue2.update_done_ratio assert_equal 50, @issue.read_attribute(:done_ratio) assert_equal 0, @issue2.read_attribute(:done_ratio)