Skip to content

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

Fix a missing case of invalid work values

Christophe Bliardcc23df9c5bc1
diff --git a/app/services/work_packages/set_attributes_service/derive_progress_values_base.rb b/app/services/work_packages/set_attributes_service/derive_progress_values_base.rb
index 9c637bc96f2..7e87d9b36fb 100644
--- a/app/services/work_packages/set_attributes_service/derive_progress_values_base.rb
+++ b/app/services/work_packages/set_attributes_service/derive_progress_values_base.rb
@@ -30,8 +30,6 @@ class WorkPackages::SetAttributesService
class DeriveProgressValuesBase
attr_reader :work_package
- PROGRESS_ATTRIBUTES = %i[work remaining_work percent_complete].freeze
-
def initialize(work_package)
@work_package = work_package
end
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.rb
index 9dafb8c9289..590b4bf8854 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
@@ -119,11 +119,9 @@ class WorkPackages::SetAttributesService
end
def remaining_work_set_greater_than_work?
- attributes_from_user == %i[remaining_work] && work && remaining_work && remaining_work > work
- end
-
- def attributes_from_user
- @attributes_from_user ||= PROGRESS_ATTRIBUTES.filter { |attr| public_send(:"#{attr}_came_from_user?") }
+ remaining_work_came_from_user? \
+ && !percent_complete_came_from_user? \
+ && work && remaining_work && remaining_work > work
end
def work_set_and_no_user_inputs_provided_for_both_remaining_work_and_percent_complete?
diff --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.rb
index 3f6ad4a78cf..c23fd90a3c9 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
@@ -207,6 +207,14 @@ RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesWorkBased
description: "is an error state (to be detected by contract), and % Complete is kept"
end
+ context "when work and remaining work are both changed so that work is lower than remaining work" do
+ let(:set_attributes) { { estimated_hours: 2, remaining_hours: 9 } }
+ let(:expected_kept_attributes) { %w[done_ratio] }
+
+ include_examples "update progress values",
+ description: "is an error state (to be detected by contract), and % Complete is kept"
+ end
+
context "when work and remaining work are both changed to values with more than 2 decimals" do
let(:set_attributes) { { estimated_hours: 10.123456, remaining_hours: 5.6789 } }
let(:expected_derived_attributes) { { estimated_hours: 10.12, remaining_hours: 5.68, done_ratio: 44 } }