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
Unset work when remaining work is unset
Christophe Bliardfc0828509c50
diff --git a/app/services/work_packages/set_attributes_service/derive_progress_values_work_based.rb b/app/services/work_packages/set_attributes_service/derive_progress_values_work_based.rbindex 590b4bf8854..a29ba12e5fe 100644--- a/app/services/work_packages/set_attributes_service/derive_progress_values_work_based.rb+++ b/app/services/work_packages/set_attributes_service/derive_progress_values_work_based.rb@@ -67,11 +67,16 @@ class WorkPackages::SetAttributesServiceenddef update_work- return if work_set_and_no_user_inputs_provided_for_both_remaining_work_and_percent_complete?return if remaining_work_unset? && percent_complete_unset?return if percent_complete == 100 # would be Infinity if computed when % complete is 100%-- self.work = work_from_percent_complete_and_remaining_work+ return unless work_can_be_derived?++ self.work =+ if remaining_work_unset?+ nil+ else+ work_from_percent_complete_and_remaining_work+ endend# rubocop:disable Metrics/AbcSize,Metrics/PerceivedComplexity@@ -108,8 +113,6 @@ class WorkPackages::SetAttributesServiceenddef work_from_percent_complete_and_remaining_work- return if remaining_work_unset?-remaining_percent_complete = 1.0 - ((percent_complete || 0) / 100.0)remaining_work / remaining_percent_completeend@@ -119,13 +122,15 @@ class WorkPackages::SetAttributesServiceenddef remaining_work_set_greater_than_work?- remaining_work_came_from_user? \+ (work_was_unset? || remaining_work_came_from_user?) \&& !percent_complete_came_from_user? \&& work && remaining_work && remaining_work > workend- def work_set_and_no_user_inputs_provided_for_both_remaining_work_and_percent_complete?- work_set? && (remaining_work_not_provided_by_user? || percent_complete_not_provided_by_user?)+ def work_can_be_derived?+ work_unset? \+ || (remaining_work_came_from_user? && percent_complete_came_from_user?) \+ || (remaining_work_unset? && remaining_work_came_from_user?)endendenddiff --git a/spec/services/work_packages/set_attributes_service/derive_progress_values_work_based_spec.rb b/spec/services/work_packages/set_attributes_service/derive_progress_values_work_based_spec.rbindex c23fd90a3c9..a1e8c55bcbb 100644--- a/spec/services/work_packages/set_attributes_service/derive_progress_values_work_based_spec.rb+++ b/spec/services/work_packages/set_attributes_service/derive_progress_values_work_based_spec.rb@@ -89,10 +89,10 @@ RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesWorkBasedcontext "when remaining work is unset" dolet(:set_attributes) { { remaining_hours: nil } }- let(:expected_derived_attributes) { { done_ratio: nil } }- let(:expected_kept_attributes) { %w[estimated_hours] }+ let(:expected_derived_attributes) { { estimated_hours: nil } }+ let(:expected_kept_attributes) { %w[done_ratio] }- include_examples "update progress values", description: "keeps work, and unsets % complete"+ include_examples "update progress values", description: "keeps % complete, and unsets work"endcontext "when % complete is unset" do@@ -435,6 +435,15 @@ RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesWorkBasedinclude_examples "update progress values", description: "remaining work is kept and work is updated accordingly"end++ context "when % complete is changed to 100%" do+ let(:set_attributes) { { done_ratio: 100 } }+ let(:expected_kept_attributes) { %w[estimated_hours remaining_hours] }++ include_examples "update progress values",+ description: "work and remaining work are kept because work cannot be derived " \+ "(error state to be detected by contract)"+ endendcontext "given a work package with work being set, and remaining work and % complete being unset" do@@ -458,7 +467,7 @@ RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesWorkBasedlet(:expected_kept_attributes) { %w[done_ratio] }include_examples "update progress values",- description: "% complete is kept and remaining work is kept unset and not recomputed" \+ description: "% complete is kept and remaining work is kept unset and not recomputed " \"(error state to be detected by contract)"end@@ -498,6 +507,15 @@ RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesWorkBaseddescription: "remaining work is kept to the same value and % complete is updated accordingly"end+ context "when work is set lower than remaining work" do+ let(:set_attributes) { { estimated_hours: 1.0 } }+ let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }++ include_examples "update progress values",+ description: "is an error state (to be detected by contract), " \+ "and % complete and remaining work are kept"+ end+context "when work is changed to a negative value" dolet(:set_attributes) { { estimated_hours: -1.0 } }let(:expected_kept_attributes) { %w[remaining_hours done_ratio] }diff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rbindex abaf3ff1fae..b7ffa0a2883 100644--- a/spec/services/work_packages/set_attributes_service_spec.rb+++ b/spec/services/work_packages/set_attributes_service_spec.rb@@ -211,9 +211,9 @@ RSpec.describe WorkPackages::SetAttributesService,context "when remaining work is unset" dolet(:call_attributes) { { remaining_hours: nil } }- let(:expected_attributes) { { estimated_hours: 10.0, done_ratio: nil } }+ let(:expected_attributes) { { estimated_hours: nil, done_ratio: 70 } }- it_behaves_like "service call", description: "keeps work, and unsets % complete"+ it_behaves_like "service call", description: "keeps % complete, and unsets work"endcontext "when work is increased" do