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

Avoid % complete errors when remaining work exceeds work

Christophe Bliard321a4f153168
diff --git a/app/contracts/work_packages/base_contract.rb b/app/contracts/work_packages/base_contract.rb
index 8b3dfd3f9a3..dfdf56eba60 100644
--- a/app/contracts/work_packages/base_contract.rb
+++ b/app/contracts/work_packages/base_contract.rb
@@ -387,6 +387,8 @@ module WorkPackages
end
def validate_percent_complete_is_set_when_work_and_remaining_work_are_set
+ return if remaining_work_exceeds_work? # avoid too many error messages at the same time
+
if work_set_and_valid? && remaining_work_set_and_valid? && work != 0 && percent_complete_unset?
errors.add(:done_ratio, :must_be_set_when_work_and_remaining_work_are_set)
end
diff --git a/spec/contracts/work_packages/base_contract_spec.rb b/spec/contracts/work_packages/base_contract_spec.rb
index 7b9e7f29985..0c673e26de2 100644
--- a/spec/contracts/work_packages/base_contract_spec.rb
+++ b/spec/contracts/work_packages/base_contract_spec.rb
@@ -578,6 +578,18 @@ RSpec.describe WorkPackages::BaseContract,
end
end
+ context "when remaining work exceeds work and done_ratio is unset" do
+ let(:estimated_hours) { 5.0 }
+ let(:remaining_hours) { 6.0 }
+ let(:done_ratio) { nil }
+
+ # no errors should be reported for % complete in this case to not overload
+ # the progress modal with error messages.
+ include_examples "contract is invalid", estimated_hours: :cant_be_inferior_to_remaining_work,
+ remaining_hours: :cant_exceed_work,
+ done_ratio: nil
+ end
+
context "when all three unset" do
let(:estimated_hours) { nil }
let(:remaining_hours) { nil }