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 % complete rounding issue

Christophe Bliardc65835e4e8a2
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 eb861402dbb..4485f88df52 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
@@ -76,14 +76,13 @@ class WorkPackages::SetAttributesService
def compute_percent_complete
# do not change % complete if the progress values are invalid
- if invalid_progress_values?
- return percent_complete
- end
+ return percent_complete if invalid_progress_values?
+ return nil if work.zero?
completed_work = work - remaining_work
completion_ratio = completed_work.to_f / work
- (completion_ratio * 100).round(2)
+ (completion_ratio * 100).round
end
def invalid_progress_values?
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 a2403449ce5..3a617789738 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
@@ -149,7 +149,7 @@ RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesWorkBased
# work changed by -2h
let(:set_attributes) { { estimated_hours: 10.0 - 2.0 } }
let(:expected_derived_attributes) do
- { remaining_hours: 3.0 - 2.0, done_ratio: 87 }
+ { remaining_hours: 3.0 - 2.0, done_ratio: 88 }
end
include_examples "update progress values",
@@ -201,7 +201,7 @@ RSpec.describe WorkPackages::SetAttributesService::DeriveProgressValuesWorkBased
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: 43 } }
+ let(:expected_derived_attributes) { { estimated_hours: 10.12, remaining_hours: 5.68, done_ratio: 44 } }
include_examples "update progress values", description: "rounds work and remaining work to 2 decimals " \
"and updates % complete accordingly"