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
Unset % Complete when work is 0h
Christophe Bliard6036a720df32
diff --git a/app/workers/work_packages/update_progress_job.rb b/app/workers/work_packages/update_progress_job.rbindex 96a7f7fa5d9..37d4b692cfc 100644--- a/app/workers/work_packages/update_progress_job.rb+++ b/app/workers/work_packages/update_progress_job.rb@@ -89,33 +89,20 @@ class WorkPackages::UpdateProgressJob < ApplicationJobenddef fix_remaining_work_exceeding_work- # avoid a division by zero when work and remaining work are both zero in- # `#derive_p_complete_from_work_and_remaining_work` method.execute(<<~SQL.squish)UPDATE temp_wp_progress_values- SET done_ratio = 0- WHERE remaining_hours = estimated_hours- SQL- execute(<<~SQL.squish)- UPDATE temp_wp_progress_values- SET remaining_hours = estimated_hours,- done_ratio = 0+ SET remaining_hours = CASE+ WHEN done_ratio IS NULL THEN estimated_hours+ ELSE ROUND((estimated_hours - (estimated_hours * done_ratio / 100.0))::numeric, 2)+ ENDWHERE remaining_hours > estimated_hours- AND done_ratio IS NULL- SQL- execute(<<~SQL.squish)- UPDATE temp_wp_progress_values- SET remaining_hours = ROUND((estimated_hours - (estimated_hours * done_ratio / 100.0))::numeric, 2)- WHERE remaining_hours > estimated_hours- AND done_ratio IS NOT NULLSQLenddef fix_only_work_being_setexecute(<<~SQL.squish)UPDATE temp_wp_progress_values- SET remaining_hours = estimated_hours,- done_ratio = 0+ SET remaining_hours = estimated_hoursWHERE estimated_hours IS NOT NULLAND remaining_hours IS NULLAND done_ratio IS NULL@@ -125,8 +112,7 @@ class WorkPackages::UpdateProgressJob < ApplicationJobdef fix_only_remaining_work_being_setexecute(<<~SQL.squish)UPDATE temp_wp_progress_values- SET estimated_hours = remaining_hours,- done_ratio = 0+ SET estimated_hours = remaining_hoursWHERE estimated_hours IS NULLAND remaining_hours IS NOT NULLAND done_ratio IS NULL@@ -156,12 +142,12 @@ class WorkPackages::UpdateProgressJob < ApplicationJobdef derive_p_complete_from_work_and_remaining_workexecute(<<~SQL.squish)UPDATE temp_wp_progress_values- SET done_ratio = (estimated_hours - remaining_hours) * 100 / estimated_hours- WHERE estimated_hours IS NOT NULL- AND remaining_hours IS NOT NULL- AND (- done_ratio IS NULL OR (estimated_hours > remaining_hours)- )+ SET done_ratio = CASE+ WHEN estimated_hours = 0 THEN NULL+ ELSE (estimated_hours - remaining_hours) * 100 / estimated_hours+ END+ WHERE estimated_hours >= 0+ AND remaining_hours >= 0SQLenddiff --git a/spec/migrations/update_progress_calculation_spec.rb b/spec/migrations/update_progress_calculation_spec.rbindex b6d7340a946..fc35b4efd60 100644--- a/spec/migrations/update_progress_calculation_spec.rb+++ b/spec/migrations/update_progress_calculation_spec.rb@@ -200,7 +200,7 @@ RSpec.describe UpdateProgressCalculation, type: :model dosubject | work | remaining work | % completewp only w set | 10h | 10h | 0%wp both w and pc set | 10h | 10h | 0%- wp only w set 0h | 0h | 0h | 0%+ wp only w set 0h | 0h | 0h |TABLE)end@@ -219,7 +219,7 @@ RSpec.describe UpdateProgressCalculation, type: :model dosubject | work | remaining work | % completewp only rw set | 4h | 4h | 0%wp both rw and pc set | 4h | 4h | 0%- wp only rw set 0h | 0h | 0h | 0%+ wp only rw set 0h | 0h | 0h |TABLE)end@@ -259,9 +259,9 @@ RSpec.describe UpdateProgressCalculation, type: :model doto: <<~TABLEsubject | work | remaining work | % completewp both w and rw set | 10h | 10h | 0%- wp both w and rw set 0h | 0h | 0h | 0%+ wp both w and rw set 0h | 0h | 0h |wp all set inconsistent | 10h | 10h | 0%- wp all set inconsistent 0h| 0h | 0h | 0%+ wp all set inconsistent 0h| 0h | 0h |TABLE)end@@ -318,7 +318,7 @@ RSpec.describe UpdateProgressCalculation, type: :model doto: <<~TABLEsubject | work | remaining work | % completewp only w set | 10h | 10h | 0%- wp only w set 0h | 0h | 0h | 0%+ wp only w set 0h | 0h | 0h |TABLE)end@@ -335,7 +335,7 @@ RSpec.describe UpdateProgressCalculation, type: :model doto: <<~TABLEsubject | work | remaining work | % completewp only rw set | 4h | 4h | 0%- wp only rw set 0h | 0h | 0h | 0%+ wp only rw set 0h | 0h | 0h |TABLE)end@@ -367,7 +367,7 @@ RSpec.describe UpdateProgressCalculation, type: :model doto: <<~TABLEsubject | work | remaining work | % completewp both w and pc set | 10h | 4h | 60%- wp both w and pc set 0h | 0h | 0h | 0%+ wp both w and pc set 0h | 0h | 0h |TABLE)end@@ -388,7 +388,7 @@ RSpec.describe UpdateProgressCalculation, type: :model dowp both rw and pc set | 10h | 4h | 60%wp both rw and pc set 0% | 4h | 4h | 0%wp both rw and pc set dec | 12.12h | 4h | 67%- wp both rw and pc set 0h | 0h | 0h | 0%+ wp both rw and pc set 0h | 0h | 0h |TABLE)end@@ -437,7 +437,7 @@ RSpec.describe UpdateProgressCalculation, type: :model doto: <<~TABLEsubject | work | remaining work | % completewp both w and rw set | 10h | 10h | 0%- wp both w and rw set 0h | 0h | 0h | 0%+ wp both w and rw set 0h | 0h | 0h |TABLE)end@@ -488,7 +488,7 @@ RSpec.describe UpdateProgressCalculation, type: :model dosubject | work | remaining work | % completewp all set consistent | 10h | 10h | 0%wp all set inconsistent | 10h | 10h | 0%- wp all set 0h | 0h | 0h | 0%+ wp all set 0h | 0h | 0h |TABLE)enddiff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rbindex 6fedf2e13bd..08748126414 100644--- a/spec/services/work_packages/set_attributes_service_spec.rb+++ b/spec/services/work_packages/set_attributes_service_spec.rb@@ -283,6 +283,16 @@ RSpec.describe WorkPackages::SetAttributesService,description: "remaining work is increased by the same amount, and % complete is updated accordingly"end+ context "when work is set to 0h" do+ let(:call_attributes) { { estimated_hours: 0 } }+ let(:expected_attributes) do+ { remaining_hours: 0, done_ratio: nil }+ end++ it_behaves_like "service call",+ description: "remaining work is set to 0h and % Complete is unset"+ end+context "when work is decreased" do# work changed by -2hlet(:call_attributes) { { estimated_hours: 10.0 - 2.0 } }