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
Keep due date when duration is 0 or negative
Christophe Bliardbaed10565199
diff --git a/app/contracts/work_packages/base_contract.rb b/app/contracts/work_packages/base_contract.rbindex 55b20e962f4..e271fd31d09 100644--- a/app/contracts/work_packages/base_contract.rb+++ b/app/contracts/work_packages/base_contract.rb@@ -507,7 +507,7 @@ module WorkPackagesenddef validate_duration_matches_dates- return unless calculated_duration && model.duration+ return unless calculated_duration && model.duration && model.duration > 0if calculated_duration > model.durationerrors.add :duration, :smaller_than_datesdiff --git a/app/services/work_packages/set_attributes_service.rb b/app/services/work_packages/set_attributes_service.rbindex 6e9fa9fd7d9..b4905c392f4 100644--- a/app/services/work_packages/set_attributes_service.rb+++ b/app/services/work_packages/set_attributes_service.rb@@ -424,16 +424,16 @@ class WorkPackages::SetAttributesService < BaseServices::SetAttributesendend- def duration_assignable?- work_package&.duration.is_a?(Integer) && work_package.duration > 0- end-def reuse_current_due_date?return false if work_package.due_date.nil?return true if work_package.ignore_non_working_days_came_from_user?# use due date only if duration cannot be used- work_package.duration.nil?+ work_package.duration.nil? || !duration_assignable?+ end++ def duration_assignable?+ work_package&.duration.is_a?(Integer) && work_package.duration > 0enddef work_packagediff --git a/spec/services/work_packages/set_attributes_service_spec.rb b/spec/services/work_packages/set_attributes_service_spec.rbindex b3bc0b32424..33c5158b44c 100644--- a/spec/services/work_packages/set_attributes_service_spec.rb+++ b/spec/services/work_packages/set_attributes_service_spec.rb@@ -1078,7 +1078,30 @@ RSpec.describe WorkPackages::SetAttributesService,endend- context "when the work package has a soonest_start from a predecessor (Regression #63598)" do+ context "when the work package has a soonest_start from a predecessor and a due date (Regression #63598)" do+ before do+ allow(instance).to receive(:new_start_date).and_return(Time.zone.yesterday)+ end++ it_behaves_like "service call" do+ it "keeps the dates and duration values (error to be detected by contract)" do+ subject++ expect(work_package.start_date)+ .to eq(Time.zone.yesterday)+ expect(work_package.due_date)+ .to eq(Time.zone.today + 5.days)+ expect(work_package.duration)+ .to eq(0)+ end+ end+ end++ context "when the work package has a soonest_start from a predecessor and no due date (Regression #63598)" do+ let(:work_package) do+ build_stubbed(:work_package, start_date: Time.zone.today, due_date: nil)+ end+before doallow(instance).to receive(:new_start_date).and_return(Time.zone.yesterday)end