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
Improve error messages with invalid progress values
Christophe Bliard711846d6f8cc
diff --git a/app/contracts/work_packages/base_contract.rb b/app/contracts/work_packages/base_contract.rbindex 2ffdc13dd8b..8a20b9251ff 100644--- a/app/contracts/work_packages/base_contract.rb+++ b/app/contracts/work_packages/base_contract.rb@@ -382,7 +382,7 @@ module WorkPackages# rubocop:disable Metrics/AbcSizedef validate_percent_complete_matches_work_and_remaining_workreturn if WorkPackage.status_based_mode? || percent_complete_unset? || work == 0- return if remaining_work_exceeds_work? # avoid too many error messages at the same time+ return if invalid_work_or_remaining_work_values? # avoid too many error messages at the same timereturn unless work_set? && remaining_work_set?work_done = work - remaining_work@@ -434,8 +434,14 @@ module WorkPackagesremaining_work.nil?end+ def invalid_work_or_remaining_work_values?+ (work_set? && work.negative?) ||+ (remaining_work_set? && remaining_work.negative?) ||+ remaining_work_exceeds_work?+ end+def remaining_work_exceeds_work?- work_set? && remaining_work_set? && remaining_work > work+ work_set_and_valid? && remaining_work_set_and_valid? && remaining_work > workenddef percent_completediff --git a/spec/contracts/work_packages/base_contract_spec.rb b/spec/contracts/work_packages/base_contract_spec.rbindex b87fdb7c7e2..e765b1fec51 100644--- a/spec/contracts/work_packages/base_contract_spec.rb+++ b/spec/contracts/work_packages/base_contract_spec.rb@@ -500,15 +500,45 @@ RSpec.describe WorkPackages::BaseContract,done_ratio: nilend- context "when unset while remaining work is set and work is set to an invalid value" do+ context "when set while work is set and remaining work is set to a negative value" do+ let(:estimated_hours) { 4 }+ let(:remaining_hours) { -3 }+ let(:done_ratio) { 50 }++ include_examples "contract is invalid", estimated_hours: nil,+ remaining_hours: :greater_than_or_equal_to,+ done_ratio: nil+ end++ context "when unset while remaining work is set and work is set to a negative value" dolet(:estimated_hours) { -4 }let(:remaining_hours) { 3 }let(:done_ratio) { nil }- it_behaves_like "contract is invalid", estimated_hours: %i[cant_be_inferior_to_remaining_work greater_than_or_equal_to],+ it_behaves_like "contract is invalid", estimated_hours: :greater_than_or_equal_to,remaining_hours: nil,done_ratio: nilend++ context "when set while remaining work is set and work is set to a negative value" do+ let(:estimated_hours) { -4 }+ let(:remaining_hours) { 3 }+ let(:done_ratio) { 50 }++ it_behaves_like "contract is invalid", estimated_hours: :greater_than_or_equal_to,+ remaining_hours: nil,+ done_ratio: nil+ end++ context "when set while work and remaining work are both set to a negative values (and work > remaining work)" do+ let(:estimated_hours) { -4 }+ let(:remaining_hours) { -12 }+ let(:done_ratio) { 50 }++ it_behaves_like "contract is invalid", estimated_hours: :greater_than_or_equal_to,+ remaining_hours: :greater_than_or_equal_to,+ done_ratio: nil+ endendend