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

[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.rb
index 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::Job
fix_remaining_work_exceeding_work
fix_only_work_being_set
fix_only_remaining_work_being_set
- derive_unset_remaining_work_from_work_and_p_complete
derive_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_complete
when "status"
set_p_complete_from_status
fix_remaining_work_set_with_100p_complete
@@ -97,32 +98,26 @@ class WorkPackages::Progress::MigrateValuesJob < WorkPackages::Progress::Job
SQL
end
- def fix_only_remaining_work_being_set
+ def fix_percent_complete_and_remaining_work_when_work_is_0h
execute(<<~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 = 0
SQL
end
- def derive_unset_remaining_work_from_work_and_p_complete
+ def fix_only_remaining_work_being_set
execute(<<~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 NULL
SQL
end
- def derive_p_complete_from_work_and_remaining_work
+ def derive_unset_p_complete_from_work_and_remaining_work
execute(<<~SQL.squish)
UPDATE temp_wp_progress_values
SET done_ratio = CASE
@@ -131,6 +126,7 @@ class WorkPackages::Progress::MigrateValuesJob < WorkPackages::Progress::Job
END
WHERE estimated_hours >= 0
AND remaining_hours >= 0
+ AND done_ratio IS NULL
SQL
end
diff --git a/spec/migrations/update_progress_calculation_spec.rb b/spec/migrations/update_progress_calculation_spec.rb
index 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 do
wp both w and pc set | 10h | | 60%
wp only w set 0h | 0h | |
TABLE
+ # % Complete is discarded and derived because of the "disabled" mode
to: <<~TABLE
subject | work | remaining work | % complete
wp only w set | 10h | 10h | 0%
@@ -213,6 +214,7 @@ RSpec.describe UpdateProgressCalculation, type: :model do
wp both rw and pc set | | 4h | 60%
wp only rw set 0h | | 0h |
TABLE
+ # % Complete is discarded and derived because of the "disabled" mode
to: <<~TABLE
subject | work | remaining work | % complete
wp only rw set | 4h | 4h | 0%
@@ -233,6 +235,7 @@ RSpec.describe UpdateProgressCalculation, type: :model do
wp all set consistent | 10h | 4h | 60%
wp all set inconsistent | 10h | 1h | 10%
TABLE
+ # % Complete is discarded and derived because of the "disabled" mode
to: <<~TABLE
subject | work | remaining work | % complete
wp both w and rw set | 10h | 4h | 60%
@@ -254,6 +257,7 @@ RSpec.describe UpdateProgressCalculation, type: :model do
wp all set inconsistent | 10h | 10h | 60%
wp all set inconsistent 0h| 0h | 0h | 60%
TABLE
+ # % Complete is discarded and derived because of the "disabled" mode
to: <<~TABLE
subject | work | remaining work | % complete
wp both w and rw set | 10h | 10h | 0%
@@ -273,6 +277,7 @@ RSpec.describe UpdateProgressCalculation, type: :model do
wp 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" mode
to: <<~TABLE
subject | work | remaining work | % complete
wp both w and big rw set | 10h | 10h | 0%
@@ -493,7 +498,7 @@ RSpec.describe UpdateProgressCalculation, type: :model do
to: <<~TABLE
subject | work | remaining work | % complete
wp 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 do
to: <<~TABLE
subject | work | remaining work | % complete
wp 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 do
run_migration
end
- 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)" do
expect_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 | | | |
TABLE
end
@@ -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%" do
expect(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]
end
end
end