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
Clear % complete when work is 0h when switching to work-based mode
Christophe Bliardf0f1e9eca663
diff --git a/app/workers/work_packages/progress/apply_statuses_change_job.rb b/app/workers/work_packages/progress/apply_statuses_change_job.rbindex 964a0aada87..affb1979cea 100644--- a/app/workers/work_packages/progress/apply_statuses_change_job.rb+++ b/app/workers/work_packages/progress/apply_statuses_change_job.rb@@ -58,22 +58,27 @@ class WorkPackages::Progress::ApplyStatusesChangeJob < WorkPackages::Progress::J@changes = changeswith_temporary_progress_table do- if WorkPackage.use_status_for_done_ratio?- set_p_complete_from_status- if OpenProject::FeatureDecisions.percent_complete_edition_active?- fix_remaining_work_set_with_100p_complete- derive_unset_work_from_remaining_work_and_p_complete- end- derive_remaining_work_from_work_and_p_complete- end+ adjust_progress_valuesupdate_totals-copy_progress_values_to_work_packages_and_update_journals(journal_cause)endendprivate+ def adjust_progress_values+ if WorkPackage.work_based_mode?+ clear_percent_complete_when_0h_work+ elsif WorkPackage.status_based_mode?+ set_p_complete_from_status+ if OpenProject::FeatureDecisions.percent_complete_edition_active?+ fix_remaining_work_set_with_100p_complete+ derive_unset_work_from_remaining_work_and_p_complete+ end+ derive_remaining_work_from_work_and_p_complete+ end+ end+def journal_causeassert_valid_cause_type!@@ -113,4 +118,12 @@ class WorkPackages::Progress::ApplyStatusesChangeJob < WorkPackages::Progress::Jraise ArgumentError, "changes must be provided"endend++ def clear_percent_complete_when_0h_work+ execute(<<~SQL.squish)+ UPDATE temp_wp_progress_values+ SET done_ratio = NULL+ WHERE estimated_hours = 0+ SQL+ endenddiff --git a/spec/workers/work_packages/progress/apply_statuses_change_job_pre_14_4_without_percent_complete_edition_spec.rb b/spec/workers/work_packages/progress/apply_statuses_change_job_pre_14_4_without_percent_complete_edition_spec.rbindex 0c50c8c6030..aa0607eb1ab 100644--- a/spec/workers/work_packages/progress/apply_statuses_change_job_pre_14_4_without_percent_complete_edition_spec.rb+++ b/spec/workers/work_packages/progress/apply_statuses_change_job_pre_14_4_without_percent_complete_edition_spec.rb@@ -97,6 +97,27 @@ RSpec.describe WorkPackages::Progress::ApplyStatusesChangeJob, "pre 14.4 withoutendend+ context "when some work packages have work set to 0h and a % complete value being set" do+ it "clears the % complete valuedoes not change any of their progress values" do+ expect_performing_job_changes(+ from: <<~TABLE,+ hierarchy | status | work | remaining work | % complete+ wp 10h 40% | To do (0%) | 10h | 6h | 40%+ wp 0h 0% | To do (0%) | 0h | 0h | 0%+ wp 0h 40% | Doing (40%) | 0h | 0h | 40%+ wp 0h 100% | Done (100%) | 0h | 0h | 100%+ TABLE+ to: <<~TABLE+ subject | status | work | remaining work | % complete+ wp 10h 40% | To do (0%) | 10h | 6h | 40%+ wp 0h 0% | To do (0%) | 0h | 0h |+ wp 0h 40% | Doing (40%) | 0h | 0h |+ wp 0h 100% | Done (100%) | 0h | 0h |+ TABLE+ )+ end+ end+context "when a status is being excluded from progress calculation" doit "computes totals of the parent having work when all children are excluded" doexpect_performing_job_changes(diff --git a/spec/workers/work_packages/progress/apply_statuses_change_job_spec.rb b/spec/workers/work_packages/progress/apply_statuses_change_job_spec.rbindex 7d45154f1cd..dbcf01d1403 100644--- a/spec/workers/work_packages/progress/apply_statuses_change_job_spec.rb+++ b/spec/workers/work_packages/progress/apply_statuses_change_job_spec.rb@@ -28,7 +28,8 @@require "rails_helper"-RSpec.describe WorkPackages::Progress::ApplyStatusesChangeJob do+RSpec.describe WorkPackages::Progress::ApplyStatusesChangeJob,+ with_flag: { percent_complete_edition: true } doshared_let(:author) { create(:user) }shared_let(:priority) { create(:priority, name: "Normal") }shared_let(:project) { create(:project, name: "Main project") }@@ -94,6 +95,27 @@ RSpec.describe WorkPackages::Progress::ApplyStatusesChangeJob doendend+ context "when some work packages have work set to 0h and a % complete value being set" do+ it "clears the % complete valuedoes not change any of their progress values" do+ expect_performing_job_changes(+ from: <<~TABLE,+ hierarchy | status | work | remaining work | % complete+ wp 10h 40% | To do (0%) | 10h | 6h | 40%+ wp 0h 0% | To do (0%) | 0h | 0h | 0%+ wp 0h 40% | Doing (40%) | 0h | 0h | 40%+ wp 0h 100% | Done (100%) | 0h | 0h | 100%+ TABLE+ to: <<~TABLE+ subject | status | work | remaining work | % complete+ wp 10h 40% | To do (0%) | 10h | 6h | 40%+ wp 0h 0% | To do (0%) | 0h | 0h |+ wp 0h 40% | Doing (40%) | 0h | 0h |+ wp 0h 100% | Done (100%) | 0h | 0h |+ TABLE+ )+ end+ end+context "when a status is being excluded from progress calculation" doit "computes totals of the parent having work when all children are excluded" doexpect_performing_job_changes(