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
[57990] Preserve % Complete over Remaining work when migrating
Christophe Bliardeb9283507ffc
diff --git a/app/workers/work_packages/progress/migrate_values_job.rb b/app/workers/work_packages/progress/migrate_values_job.rbindex 6fcf14aad81..1ff8ef16e52 100644--- a/app/workers/work_packages/progress/migrate_values_job.rb+++ b/app/workers/work_packages/progress/migrate_values_job.rb@@ -55,9 +55,10 @@ class WorkPackages::Progress::MigrateValuesJob < WorkPackages::Progress::Jobfix_remaining_work_exceeding_workfix_only_work_being_setfix_only_remaining_work_being_set- derive_unset_remaining_work_from_work_and_p_completederive_unset_work_from_remaining_work_and_p_complete- derive_p_complete_from_work_and_remaining_work+ derive_unset_p_complete_from_work_and_remaining_work+ fix_percent_complete_and_remaining_work_when_work_is_0h+ derive_remaining_work_from_work_and_p_completewhen "status"set_p_complete_from_statusfix_remaining_work_set_with_100p_complete@@ -97,32 +98,26 @@ class WorkPackages::Progress::MigrateValuesJob < WorkPackages::Progress::JobSQLend- def fix_only_remaining_work_being_set+ def fix_percent_complete_and_remaining_work_when_work_is_0hexecute(<<~SQL.squish)UPDATE temp_wp_progress_values- SET estimated_hours = remaining_hours- WHERE estimated_hours IS NULL- AND remaining_hours IS NOT NULL- AND done_ratio IS NULL+ SET remaining_hours = 0,+ done_ratio = NULL+ WHERE estimated_hours = 0SQLend- def derive_unset_remaining_work_from_work_and_p_complete+ def fix_only_remaining_work_being_setexecute(<<~SQL.squish)UPDATE temp_wp_progress_values- SET remaining_hours =- GREATEST(0,- LEAST(estimated_hours,- ROUND((estimated_hours - (estimated_hours * done_ratio / 100.0))::numeric, 2)- )- )- WHERE estimated_hours IS NOT NULL- AND remaining_hours IS NULL- AND done_ratio IS NOT NULL+ SET estimated_hours = remaining_hours+ WHERE estimated_hours IS NULL+ AND remaining_hours IS NOT NULL+ AND done_ratio IS NULLSQLend- def derive_p_complete_from_work_and_remaining_work+ def derive_unset_p_complete_from_work_and_remaining_workexecute(<<~SQL.squish)UPDATE temp_wp_progress_valuesSET done_ratio = CASE@@ -131,6 +126,7 @@ class WorkPackages::Progress::MigrateValuesJob < WorkPackages::Progress::JobENDWHERE estimated_hours >= 0AND remaining_hours >= 0+ AND done_ratio IS NULLSQLenddiff --git a/spec/migrations/update_progress_calculation_spec.rb b/spec/migrations/update_progress_calculation_spec.rbindex 81bc175b652..0c558407f92 100644--- a/spec/migrations/update_progress_calculation_spec.rb+++ b/spec/migrations/update_progress_calculation_spec.rb@@ -194,6 +194,7 @@ RSpec.describe UpdateProgressCalculation, type: :model dowp both w and pc set | 10h | | 60%wp only w set 0h | 0h | |TABLE+ # % Complete is discarded and derived because of the "disabled" modeto: <<~TABLEsubject | work | remaining work | % completewp only w set | 10h | 10h | 0%@@ -213,6 +214,7 @@ RSpec.describe UpdateProgressCalculation, type: :model dowp both rw and pc set | | 4h | 60%wp only rw set 0h | | 0h |TABLE+ # % Complete is discarded and derived because of the "disabled" modeto: <<~TABLEsubject | work | remaining work | % completewp only rw set | 4h | 4h | 0%@@ -233,6 +235,7 @@ RSpec.describe UpdateProgressCalculation, type: :model dowp all set consistent | 10h | 4h | 60%wp all set inconsistent | 10h | 1h | 10%TABLE+ # % Complete is discarded and derived because of the "disabled" modeto: <<~TABLEsubject | work | remaining work | % completewp both w and rw set | 10h | 4h | 60%@@ -254,6 +257,7 @@ RSpec.describe UpdateProgressCalculation, type: :model dowp all set inconsistent | 10h | 10h | 60%wp all set inconsistent 0h| 0h | 0h | 60%TABLE+ # % Complete is discarded and derived because of the "disabled" modeto: <<~TABLEsubject | work | remaining work | % completewp both w and rw set | 10h | 10h | 0%@@ -273,6 +277,7 @@ RSpec.describe UpdateProgressCalculation, type: :model dowp both w and big rw set | 10h | 99h |wp all set big wp | 10h | 99h | 60%TABLE+ # % Complete is discarded and derived because of the "disabled" modeto: <<~TABLEsubject | work | remaining work | % completewp both w and big rw set | 10h | 10h | 0%@@ -493,7 +498,7 @@ RSpec.describe UpdateProgressCalculation, type: :model doto: <<~TABLEsubject | work | remaining work | % completewp all set consistent | 10h | 4h | 60%- wp all set inconsistent | 10h | 1h | 90%+ wp all set inconsistent | 10h | 9h | 10%TABLE)end@@ -511,7 +516,7 @@ RSpec.describe UpdateProgressCalculation, type: :model doto: <<~TABLEsubject | work | remaining work | % completewp all set consistent | 10h | 10h | 0%- wp all set inconsistent | 10h | 10h | 0%+ wp all set inconsistent | 10h | 4h | 60%wp all set 0h | 0h | 0h |TABLE)@@ -823,14 +828,14 @@ RSpec.describe UpdateProgressCalculation, type: :model dorun_migrationend- it "fixes the total values and sets ∑ % complete to nil (not 0) but keeps % complete (unless wrong)" do+ it "fixes the total values and sets ∑ % complete to nil (not 0) and keeps % complete (unless wrong)" doexpect_work_packages(table_work_packages.map(&:reload), <<~TABLE)subject | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete |wp zero | | | 0 | | | |wp correct | 100h | 50h | 50 | 100h | 50h | 50 |wp correct child | | | | | | |- wp wrong | | | 90 | 100h | 50h | 50 |- wp wrong child | 100h | 50h | 50 | | | |+ wp wrong | | | 90 | 100h | 80h | 20 |+ wp wrong child | 100h | 80h | 20 | | | |TABLEend@@ -858,14 +863,14 @@ RSpec.describe UpdateProgressCalculation, type: :model do.to eql [nil, 50]end- it "creates a journal for the work package transitioning ∑ % complete from 90 to 50" do+ it "creates a journal for the work package transitioning ∑ % complete from 90% to 20%" doexpect(wp_wrong.journals.count).to eq(2)expect(wp_wrong.journals.first.get_changes.keys).not_to include("derived_done_ratio")expect(wp_wrong.journals.last.get_changes["derived_done_ratio"])- .to eql [nil, 50]+ .to eql [nil, 20]endendend