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
add duration to project phase
Ivan Kuchindf3f97087f56
diff --git a/app/forms/projects/life_cycles/form.rb b/app/forms/projects/life_cycles/form.rbindex 4ab76c6b1e3..15d1db460f9 100644--- a/app/forms/projects/life_cycles/form.rb+++ b/app/forms/projects/life_cycles/form.rb@@ -55,9 +55,9 @@ module Projects::LifeCyclesvalue = [model.start_date, model.finish_date].compact.join(" - ")input_attributes = { name: :date_range, value: }- if model.working_days_count+ if model.durationinput_attributes[:caption] =- I18n.t("project_phase.working_days_count", count: model.working_days_count)+ I18n.t("project_phase.duration", count: model.duration)endform.range_date_picker **base_input_attributes, **input_attributesdiff --git a/app/models/project/phase.rb b/app/models/project/phase.rbindex 7a2c4e794a6..dbc3a37f3fd 100644--- a/app/models/project/phase.rb+++ b/app/models/project/phase.rb@@ -33,6 +33,7 @@ class Project::Phase < ApplicationRecordclass_name: "Project::PhaseDefinition"has_many :work_packages, inverse_of: :project_phase, dependent: :nullify+ validates :duration, presence: true, if: :range_set?validate :validate_date_rangedelegate :name,@@ -54,12 +55,6 @@ class Project::Phase < ApplicationRecordendend- def working_days_count- return nil if not_set?-- Day.working.from_range(from: start_date, to: finish_date).count- end-def date_range=(range)case rangewhen Stringdiff --git a/app/services/journals/create_service/project_phase.rb b/app/services/journals/create_service/project_phase.rbindex 718d6752651..363ec42a39a 100644--- a/app/services/journals/create_service/project_phase.rb+++ b/app/services/journals/create_service/project_phase.rb@@ -49,14 +49,16 @@ class Journals::CreateServicephase_id,start_date,finish_date,- active+ active,+ duration)SELECT#{id_from_inserted_journal_sql},project_phases.id,project_phases.start_date,project_phases.finish_date,- project_phases.active+ project_phases.active,+ project_phases.durationFROM project_phasesWHERE#{only_if_created_sql}@@ -84,6 +86,7 @@ class Journals::CreateServicephases.start_date IS DISTINCT FROM project_phase_journals.start_dateOR phases.finish_date IS DISTINCT FROM project_phase_journals.finish_dateOR phases.active IS DISTINCT FROM project_phase_journals.active+ OR phases.duration IS DISTINCT FROM project_phase_journals.durationSQLendenddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex eeb1d35a0f9..7b2297fc144 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -460,7 +460,7 @@ en:work_package_priorities:new_label: "New priority"project_phase:- working_days_count:+ duration:one: "Duration: %{count} working day"other: "Duration: %{count} working days"lists:diff --git a/db/migrate/20250411104802_add_duration_to_project_phases.rb b/db/migrate/20250411104802_add_duration_to_project_phases.rbnew file mode 100644index 00000000000..7901b5d6b5c--- /dev/null+++ b/db/migrate/20250411104802_add_duration_to_project_phases.rb@@ -0,0 +1,8 @@+# frozen_string_literal: true++class AddDurationToProjectPhases < ActiveRecord::Migration[8.0]+ def change+ add_column :project_phases, :duration, :integer, null: true+ add_column :project_phase_journals, :duration, :integer, null: true+ end+enddiff --git a/spec/factories/project_phase_factory.rb b/spec/factories/project_phase_factory.rbindex bf5e600d07d..9c50cff8467 100644--- a/spec/factories/project_phase_factory.rb+++ b/spec/factories/project_phase_factory.rb@@ -36,6 +36,7 @@ FactoryBot.define dostart_date { Date.current - 2.days }finish_date { Date.current + 2.days }+ duration { 5 }trait :skip_validate doto_create { |instance| instance.save(validate: false) }diff --git a/spec/models/project/phase_spec.rb b/spec/models/project/phase_spec.rbindex 1070f0a5c3f..1a82e665041 100644--- a/spec/models/project/phase_spec.rb+++ b/spec/models/project/phase_spec.rb@@ -124,43 +124,4 @@ RSpec.describe Project::Phase doexpect(subject.errors[:date_range]).to be_emptyendend-- describe "#working_days_count" do- it "returns nil if not_set? is true" do- allow(Day).to receive(:working)-- subject.start_date = nil- subject.finish_date = nil-- expect(subject.working_days_count).to be_nil- expect(Day).not_to have_received(:working)- end-- it "returns the correct number of days if start_date and finish_date are the same" do- subject.start_date = Time.zone.today- subject.finish_date = Time.zone.today- expect(subject.working_days_count).to eq(1)- end-- it "returns the correct number of days for a valid date range" do- subject.start_date = Date.parse("2024-11-25")- subject.finish_date = Date.parse("2024-11-27")- expect(subject.working_days_count).to eq(3)- end-- it "calls the Day.working.from_range method with the right arguments" do- subject.start_date = Date.parse("2024-11-25")- subject.finish_date = Date.parse("2024-11-27")-- allow(Day).to receive(:working).and_return(Day)- allow(Day).to receive(:from_range)- .with(from: subject.start_date, to: subject.finish_date)- .and_return([])-- expect(subject.working_days_count).to eq(0)-- expect(Day).to have_received(:working).with(no_args)- expect(Day).to have_received(:from_range).with(from: subject.start_date, to: subject.finish_date)- end- endend