OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
refactoring: reduce methods to check progress calculation mode
Christophe Bliardb36078654b44
diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rbindex 2041400006d..fa15c4ef341 100644--- a/app/controllers/statuses_controller.rb+++ b/app/controllers/statuses_controller.rb@@ -91,7 +91,7 @@ class StatusesController < ApplicationControllerdef recompute_progress_valuesattributes_triggering_recomputing = ["excluded_from_totals"]- attributes_triggering_recomputing << "default_done_ratio" if WorkPackage.use_status_for_done_ratio?+ attributes_triggering_recomputing << "default_done_ratio" if WorkPackage.status_based_mode?changes = @status.previous_changes.slice(*attributes_triggering_recomputing)return if changes.empty?diff --git a/app/controllers/work_packages/progress_controller.rb b/app/controllers/work_packages/progress_controller.rbindex 3d1831c70f4..be56a8791f6 100644--- a/app/controllers/work_packages/progress_controller.rb+++ b/app/controllers/work_packages/progress_controller.rb@@ -113,7 +113,7 @@ class WorkPackages::ProgressController < ApplicationControllerprivatedef modal_class- if WorkPackage.use_status_for_done_ratio?+ if WorkPackage.status_based_mode?WorkPackages::Progress::StatusBased::ModalBodyComponentelseWorkPackages::Progress::WorkBased::ModalBodyComponent@@ -153,7 +153,7 @@ class WorkPackages::ProgressController < ApplicationControllerenddef allowed_params- if WorkPackage.use_status_for_done_ratio?+ if WorkPackage.status_based_mode?%i[estimated_hours status_id]# two next lines to be removed in 15.0 with :percent_complete_edition feature flag removalelsif !OpenProject::FeatureDecisions.percent_complete_edition_active?diff --git a/app/models/custom_actions/actions/done_ratio.rb b/app/models/custom_actions/actions/done_ratio.rbindex 894b22d0ee5..52bad025bc8 100644--- a/app/models/custom_actions/actions/done_ratio.rb+++ b/app/models/custom_actions/actions/done_ratio.rb@@ -46,7 +46,7 @@ class CustomActions::Actions::DoneRatio < CustomActions::Actions::Baseenddef self.all- if WorkPackage.use_field_for_done_ratio?+ if WorkPackage.work_based_mode?superelse[]diff --git a/app/models/work_package.rb b/app/models/work_package.rbindex f60c2236c3b..100b19aac31 100644--- a/app/models/work_package.rb+++ b/app/models/work_package.rb@@ -212,14 +212,6 @@ class WorkPackage < ApplicationRecordSetting.work_package_done_ratio == "field"end- def self.use_status_for_done_ratio?- Setting.work_package_done_ratio == "status"- end-- def self.use_field_for_done_ratio?- Setting.work_package_done_ratio == "field"- end-def self.complete_on_status_closed?Setting.percent_complete_on_status_closed == "set_100p"end@@ -309,7 +301,7 @@ class WorkPackage < ApplicationRecordenddef done_ratio- if WorkPackage.use_status_for_done_ratio? && status && status.default_done_ratio+ if WorkPackage.status_based_mode? && status && status.default_done_ratiostatus.default_done_ratioelseread_attribute(:done_ratio)@@ -384,7 +376,7 @@ class WorkPackage < ApplicationRecord# 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 laterdef update_done_ratio_from_status- if WorkPackage.use_status_for_done_ratio? && status && status.default_done_ratio+ if WorkPackage.status_based_mode? && status && status.default_done_ratioself.done_ratio = status.default_done_ratioendenddiff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rbindex ee168d4dbd0..a013034c27b 100644--- a/app/services/work_packages/set_attributes_service.rb+++ b/app/services/work_packages/set_attributes_service.rb@@ -287,7 +287,7 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributesdef update_progress_attributesderive_progress_values_class =if OpenProject::FeatureDecisions.percent_complete_edition_active?- WorkPackage.use_status_for_done_ratio? ? DeriveProgressValuesStatusBased : DeriveProgressValuesWorkBased+ WorkPackage.status_based_mode? ? DeriveProgressValuesStatusBased : DeriveProgressValuesWorkBasedelsePre144DeriveProgressValuesenddiff --git a/app/services/work_packages/set_attributes_service/pre_14_4_derive_progress_values.rb b/app/services/work_packages/set_attributes_service/pre_14_4_derive_progress_values.rbindex 0248a413bf8..08fe1987db5 100644--- a/app/services/work_packages/set_attributes_service/pre_14_4_derive_progress_values.rb+++ b/app/services/work_packages/set_attributes_service/pre_14_4_derive_progress_values.rb@@ -41,7 +41,7 @@ class WorkPackages::SetAttributesService# From this point, copied over from 109b135b:app/services/work_packages/set_attributes_service.rb#L287-L427def update_progress_attributes- if WorkPackage.use_status_for_done_ratio?+ if WorkPackage.status_based_mode?update_done_ratioupdate_remaining_hourselsif only_percent_complete_initially_set?@@ -73,7 +73,7 @@ class WorkPackages::SetAttributesService# Unless both +remaining_hours+ and +estimated_hours+ are set, +done_ratio+ will be# considered nil.def update_done_ratio- if WorkPackage.use_status_for_done_ratio?+ if WorkPackage.status_based_mode?return unless work_package.status_id_changed?work_package.done_ratio = work_package.status.default_done_ratio@@ -133,7 +133,7 @@ class WorkPackages::SetAttributesServiceenddef update_estimated_hours- return unless WorkPackage.use_field_for_done_ratio?+ return unless WorkPackage.work_based_mode?return if work_package.estimated_hours_came_from_user?return unless work_package.remaining_hours_changed?@@ -151,9 +151,9 @@ class WorkPackages::SetAttributesService# unset the remaining hours.# rubocop:disable Metrics/PerceivedComplexitydef update_remaining_hours- if WorkPackage.use_status_for_done_ratio?+ if WorkPackage.status_based_mode?update_remaining_hours_from_percent_complete- elsif WorkPackage.use_field_for_done_ratio? &&+ elsif WorkPackage.work_based_mode? &&work_package.estimated_hours_changed?return if work_package.remaining_hours_came_from_user?return if work_package.estimated_hours&.negative?diff --git a/lib/api/v3/work_packages/work_package_representer.rb b/lib/api/v3/work_packages/work_package_representer.rbindex b5737cfef6b..14ac3de591a 100644--- a/lib/api/v3/work_packages/work_package_representer.rb+++ b/lib/api/v3/work_packages/work_package_representer.rb@@ -410,7 +410,7 @@ module APIdatetime_formatter.format_duration_from_hours(represented.remaining_hours,allow_nil: true)end,- writable: ->(*) { !WorkPackage.use_status_for_done_ratio? },+ writable: ->(*) { !WorkPackage.status_based_mode? },render_nil: falseproperty :derived_remaining_time,diff --git a/spec/factories/work_package_factory.rb b/spec/factories/work_package_factory.rbindex c740a392f14..97099bc76ed 100644--- a/spec/factories/work_package_factory.rb+++ b/spec/factories/work_package_factory.rb@@ -149,7 +149,7 @@ FactoryBot.define do# force done_ratio in status-based mode if given done_ratio is different from status defaultcallback(:after_create) do |work_package, evaluator|- next unless WorkPackage.use_status_for_done_ratio?+ next unless WorkPackage.status_based_mode?next unless evaluator.__override_names__.include?(:done_ratio)if work_package.read_attribute(:done_ratio) != evaluator.done_ratio