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

unset old total p complete values in journals

ulferts14e9142c05ee
diff --git a/app/workers/work_packages/update_progress_job.rb b/app/workers/work_packages/update_progress_job.rb
index 3b1adacb4ba..b38c3991fd3 100644
--- a/app/workers/work_packages/update_progress_job.rb
+++ b/app/workers/work_packages/update_progress_job.rb
@@ -53,6 +53,8 @@ class WorkPackages::UpdateProgressJob < ApplicationJob
update_totals
+ unset_total_p_complete
+
copy_progress_values_to_work_packages_and_update_journals
end
end
@@ -209,6 +211,33 @@ class WorkPackages::UpdateProgressJob < ApplicationJob
SQL
end
+ # The value for derived_done_ratio had been calculated wrong in the past. So prior to executing the job
+ # values in the work_packages and work_package_journals table sometimes contained wrong data.
+ # The whole job/migration is now treating the derived_done_ratio as a value newly introduced even if it, under
+ # the hood has existed before. But it was not shown in the activites before so the user would not have seen it.
+ #
+ # Because of this, all values, in the work_packages and work_package_journals table, for derived_done_ratio are
+ # reset to null.
+ #
+ # This results in two cases:
+ # * The value before has been something (most of the time 0) and is now null. This will hopefully be the
+ # majority of the cases as it would save a lot of journal creation, the slowest part of the job.
+ # For that case, the derived_done_ratio will be treated as not having changed by the job since with the rewrite
+ # the value looks to have been null before and is now null again.
+ # * The value before has been something and is now something. It could have been the same value as before. But
+ # since the job resets the value to null, it will in every case be treated as having changed (set for the first time)
+ def unset_total_p_complete
+ execute(<<~SQL)
+ UPDATE work_packages
+ SET derived_done_ratio = NULL
+ SQL
+
+ execute(<<~SQL)
+ UPDATE work_package_journals
+ SET derived_done_ratio = NULL
+ SQL
+ end
+
def copy_progress_values_to_work_packages_and_update_journals
updated_work_package_ids = copy_progress_values_to_work_packages
create_journals_for_updated_work_packages(updated_work_package_ids)
diff --git a/spec/migrations/update_progress_calculation_spec.rb b/spec/migrations/update_progress_calculation_spec.rb
index de64c2a92e5..298c045d718 100644
--- a/spec/migrations/update_progress_calculation_spec.rb
+++ b/spec/migrations/update_progress_calculation_spec.rb
@@ -74,10 +74,18 @@ RSpec.describe UpdateProgressCalculation, type: :model do
run_migration
end
- it "does not create a journal entry" do
- table_work_packages.each do |wp|
- expect(wp.journals.count).to eq(1)
- end
+ it "does create a journal entry only for the work package with a total % complete" do
+ expect(wp_all_unset.journals.count).to eq(1)
+ expect(wp_only_pc_set.journals.count).to eq(1)
+
+ # This one will receive a journal entry since we treat the total % complete field
+ # as if it was introduced by the migration (OP 14.0) even though the field existed before.
+ # But the calculation was off and we did not present the activity on the field anyway.
+ expect(wp_all_set_consistent.journals.count).to eq(2)
+
+ expect(wp_all_set_consistent.last_journal.get_changes)
+ .to include("derived_done_ratio" => [nil, 60],
+ "cause" => [nil, { "feature" => "progress_calculation_changed", "type" => "system_update" }])
end
end
@@ -685,5 +693,66 @@ RSpec.describe UpdateProgressCalculation, type: :model do
)
end
end
+
+ context "when ∑ % complete has had some values (including wrong ones)" do
+ let_work_packages(<<~TABLE)
+ hierarchy | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete |
+ wp zero | | | 0 | | | 0 |
+ wp correct | 100h | 50h | 50 | 100h | 50h | 50 |
+ wp wrong | | | 90 | 100h | 50h | 90 |
+ wp wrong child | 100h | 50h | 20 | 10h | 10h | 20 |
+ TABLE
+
+ before do
+ run_migration
+ end
+
+ it "fixes the total values and sets ∑ % complete to nil (not 0) but keeps % complete (unless wrong)" do
+ expect_work_packages(WorkPackage.all, <<~TABLE)
+ subject | work | remaining work | % complete | ∑ work | ∑ remaining work | ∑ % complete |
+ wp zero | | | 0 | | | |
+ wp correct | 100h | 50h | 50 | 100h | 50h | 50 |
+ wp wrong | | | 90 | 100h | 50h | 50 |
+ wp wrong child | 100h | 50h | 50 | 100h | 50h | 50 |
+ TABLE
+ end
+
+ it "creates no journal for the work package transitioning from 0 to nil and reworks the pre migration journals" do
+ expect(wp_zero.journals.count).to eq(1)
+
+ expect(wp_zero.journals.first.get_changes.keys)
+ .not_to include("derived_done_ratio")
+ end
+
+ it "creates a journal for the correct work package as the old ∑ % complete value has been set to null during the job" do
+ expect(wp_correct.journals.count).to eq(2)
+
+ expect(wp_correct.journals.first.get_changes.keys)
+ .not_to include("derived_done_ratio")
+
+ expect(wp_correct.journals.last.get_changes["derived_done_ratio"])
+ .to eql [nil, 50]
+ end
+
+ it "creates a journal for the work package transitioning from 90 to 50 and reworks the pre migration journals" 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]
+ end
+
+ it "creates a journal for the work package transitioning from 20 to 50 and reworks the pre migration journals" do
+ expect(wp_wrong_child.journals.count).to eq(2)
+
+ expect(wp_wrong_child.journals.first.get_changes.keys)
+ .not_to include("derived_done_ratio")
+
+ expect(wp_wrong_child.journals.last.get_changes["derived_done_ratio"])
+ .to eql [nil, 50]
+ end
+ end
end
end