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

Round remaining work computed from work and % complete

Christophe Bliard2600fb208900
diff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rb
index 60adf9cbd93..acff442134c 100644
--- a/app/services/work_packages/set_attributes_service.rb
+++ b/app/services/work_packages/set_attributes_service.rb
@@ -403,7 +403,7 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributes
return nil if work_package.done_ratio.nil? || work_package.estimated_hours.nil?
completed_work = work_package.estimated_hours * work_package.done_ratio / 100.0
- work_package.estimated_hours - completed_work
+ (work_package.estimated_hours - completed_work).round(2)
end
def set_version_to_nil
diff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rb
index eff8902fed8..6fedf2e13bd 100644
--- a/spec/services/work_packages/set_attributes_service_spec.rb
+++ b/spec/services/work_packages/set_attributes_service_spec.rb
@@ -246,8 +246,8 @@ RSpec.describe WorkPackages::SetAttributesService,
context "given a work package with work, remaining work, and % complete being set" do
before do
work_package.estimated_hours = 10.0
- work_package.remaining_hours = 6.0
- work_package.done_ratio = 40
+ work_package.remaining_hours = 3.0
+ work_package.done_ratio = 70
work_package.send(:clear_changes_information)
end
@@ -276,7 +276,7 @@ RSpec.describe WorkPackages::SetAttributesService,
# work changed by +10h
let(:call_attributes) { { estimated_hours: 10.0 + 10.0 } }
let(:expected_attributes) do
- { remaining_hours: 6.0 + 10.0, done_ratio: 20 }
+ { remaining_hours: 3.0 + 10.0, done_ratio: 35 }
end
it_behaves_like "service call",
@@ -287,7 +287,7 @@ RSpec.describe WorkPackages::SetAttributesService,
# work changed by -2h
let(:call_attributes) { { estimated_hours: 10.0 - 2.0 } }
let(:expected_attributes) do
- { remaining_hours: 6.0 - 2.0, done_ratio: 50 }
+ { remaining_hours: 3.0 - 2.0, done_ratio: 87 }
end
it_behaves_like "service call",
@@ -340,6 +340,14 @@ RSpec.describe WorkPackages::SetAttributesService,
it_behaves_like "service call", description: "updates % complete accordingly"
end
+
+ context "when work is changed and remaining work is unset" do
+ let(:call_attributes) { { estimated_hours: 8.0, remaining_hours: nil } }
+ let(:expected_attributes) { { remaining_hours: 2.4 } } # would be 2.4000000000000004 without rounding
+ let(:expected_kept_attributes) { %w[done_ratio] }
+
+ it_behaves_like "service call", description: "% complete is kept and remaining work is recomputed (and rounded)"
+ end
end
context "given a work package with work and % complete being set, and remaining work being unset" do