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

more places work_pakcage -> entity

Klaus Zanders6ff26486f336
diff --git a/modules/costs/app/components/time_entries/activity_form.rb b/modules/costs/app/components/time_entries/activity_form.rb
index 6c9f137f56e..af491adc59c 100644
--- a/modules/costs/app/components/time_entries/activity_form.rb
+++ b/modules/costs/app/components/time_entries/activity_form.rb
@@ -53,14 +53,14 @@ module TimeEntries
private
- delegate :project, :work_package, to: :model
+ delegate :project, :entity, to: :model
- def project_or_work_package_selected?
- work_package.present? || project.present?
+ def project_or_entity_selected?
+ entity.present? || project.present?
end
def placeholder_text
- I18n.t("placeholder_activity_select_work_package_first") unless project_or_work_package_selected?
+ I18n.t("placeholder_activity_select_work_package_first") unless project_or_entity_selected?
end
def activities
diff --git a/modules/costs/app/components/time_entries/entity_form.rb b/modules/costs/app/components/time_entries/entity_form.rb
index ec53256469c..bd73051da8f 100644
--- a/modules/costs/app/components/time_entries/entity_form.rb
+++ b/modules/costs/app/components/time_entries/entity_form.rb
@@ -58,14 +58,14 @@ module TimeEntries
filters: work_package_completer_filters
}
else
- f.hidden name: :work_package_id, value: model.work_package_id
+ f.hidden name: :entity_id, value: model.entity_id
end
end
private
def show_work_package_field?
- return true if model.work_package_id.nil?
+ return true if model.entity_id.nil?
@visible
end
@@ -92,7 +92,7 @@ module TimeEntries
if model.errors[:project_id].present?
model.errors[:project_id].first
else
- model.errors[:work_package]&.first
+ model.errors[:entities]&.first
end
end
diff --git a/modules/costs/app/controllers/costlog_controller.rb b/modules/costs/app/controllers/costlog_controller.rb
index 531664914d3..4a49d145d8b 100644
--- a/modules/costs/app/controllers/costlog_controller.rb
+++ b/modules/costs/app/controllers/costlog_controller.rb
@@ -57,7 +57,7 @@ class CostlogController < ApplicationController
elsif @cost_entry.save
flash[:notice] = t(:notice_cost_logged_successfully)
- redirect_back_or_default work_package_path(@cost_entry.work_package)
+ redirect_back_or_default work_package_path(@cost_entry.entity)
else
render action: :edit, status: :unprocessable_entity
end
@@ -73,7 +73,7 @@ class CostlogController < ApplicationController
elsif @cost_entry.save
flash[:notice] = t(:notice_successful_update)
- redirect_back fallback_location: work_package_path(@cost_entry.work_package)
+ redirect_back fallback_location: work_package_path(@cost_entry.entity)
else
render action: "edit"
@@ -90,7 +90,7 @@ class CostlogController < ApplicationController
if request.referer.include?("cost_reports")
redirect_to controller: "/cost_reports", action: :index
else
- redirect_back fallback_location: work_package_path(@cost_entry.work_package)
+ redirect_back fallback_location: work_package_path(@cost_entry.entity)
end
end
@@ -121,8 +121,8 @@ class CostlogController < ApplicationController
end
work_package_id = cost_entry_params.delete(:work_package_id)
- @work_package = if @cost_entry.present? && @cost_entry.work_package_id == work_package_id
- @cost_entry.work_package
+ @work_package = if @cost_entry.present? && @cost_entry.entity_type == "WorkPackage" && @cost_entry.enity_id == work_package_id
+ @cost_entry.entity
else
WorkPackage.find_by(id: work_package_id)
end
@@ -138,7 +138,7 @@ class CostlogController < ApplicationController
def new_default_cost_entry
@cost_entry = CostEntry.new.tap do |ce|
ce.project = @project
- ce.work_package = @work_package
+ ce.entity = @work_package
ce.user = User.current
ce.spent_on = Time.zone.today
# notice that cost_type is set to default cost_type in the model
@@ -147,7 +147,7 @@ class CostlogController < ApplicationController
def update_cost_entry_from_params
@cost_entry.user = @user
- @cost_entry.work_package = @work_package
+ @cost_entry.entity = @work_package
@cost_entry.cost_type = @cost_type
attributes = permitted_params.cost_entry
diff --git a/modules/costs/app/controllers/time_entries_controller.rb b/modules/costs/app/controllers/time_entries_controller.rb
index 9f8f81cdb65..ec7043c3033 100644
--- a/modules/costs/app/controllers/time_entries_controller.rb
+++ b/modules/costs/app/controllers/time_entries_controller.rb
@@ -223,7 +223,7 @@ class TimeEntriesController < ApplicationController
entry
end
else
- TimeEntry.new(project: @project, work_package: @work_package, user: User.current)
+ TimeEntry.new(project: @project, entity: @work_package, user: User.current)
end
end
end
diff --git a/modules/costs/app/models/cost_entry.rb b/modules/costs/app/models/cost_entry.rb
index 4cb9fa21d98..fd68708a572 100644
--- a/modules/costs/app/models/cost_entry.rb
+++ b/modules/costs/app/models/cost_entry.rb
@@ -74,13 +74,13 @@ class CostEntry < ApplicationRecord
end
def before_validation
- self.project = work_package.project if work_package && project.nil?
+ self.project = entity.project if entity && project.nil?
end
def validate
errors.add :units, :invalid if units&.negative?
errors.add :project_id, :invalid if project.nil?
- errors.add :work_package_id, :invalid if work_package.nil? || (project != work_package.project)
+ errors.add :entity, :invalid if entity.nil? || (project != entity.project)
errors.add :cost_type_id, :invalid if cost_type.present? && cost_type.deleted_at.present?
errors.add :user_id, :invalid if project.present? && project.users.exclude?(user) && user_id_changed?
diff --git a/modules/costs/spec/features/my_time_tracking_spec.rb b/modules/costs/spec/features/my_time_tracking_spec.rb
index 0ef3eefa785..b85bbab5108 100644
--- a/modules/costs/spec/features/my_time_tracking_spec.rb
+++ b/modules/costs/spec/features/my_time_tracking_spec.rb
@@ -45,18 +45,18 @@ RSpec.describe "my time tracking", :js do
let(:project2) { create(:project_with_types) }
let(:work_package1) { create(:work_package, project: project1) }
let(:work_package2) { create(:work_package, project: project2) }
- let!(:time_entry1) { create(:time_entry, user:, work_package: work_package1, spent_on: "2025-04-07", hours: 6.5) }
+ let!(:time_entry1) { create(:time_entry, user:, entity: work_package1, spent_on: "2025-04-07", hours: 6.5) }
let!(:time_entry2) do
- create(:time_entry, work_package: work_package1, user:, spent_on: "2025-04-09", hours: 1.0, start_time: (9 * 60) + 30,
+ create(:time_entry, entity: work_package1, user:, spent_on: "2025-04-09", hours: 1.0, start_time: (9 * 60) + 30,
time_zone:)
end
- let!(:time_entry3) { create(:time_entry, user:, work_package: work_package1, spent_on: "2025-04-14", hours: 3.0) }
- let!(:time_entry4) { create(:time_entry, user:, work_package: work_package2, spent_on: "2025-04-09", hours: 2.0) }
+ let!(:time_entry3) { create(:time_entry, user:, entity: work_package1, spent_on: "2025-04-14", hours: 3.0) }
+ let!(:time_entry4) { create(:time_entry, user:, entity: work_package2, spent_on: "2025-04-09", hours: 2.0) }
let!(:time_entry5) do
- create(:time_entry, user:, work_package: work_package2, spent_on: "2025-04-09", hours: 1.0, start_time: (13 * 60) + 30,
+ create(:time_entry, user:, entity: work_package2, spent_on: "2025-04-09", hours: 1.0, start_time: (13 * 60) + 30,
time_zone:)
end
- let!(:time_entry6) { create(:time_entry, user:, work_package: work_package2, spent_on: "2025-04-14", hours: 2.0) }
+ let!(:time_entry6) { create(:time_entry, user:, entity: work_package2, spent_on: "2025-04-14", hours: 2.0) }
let(:allow_exact_time_tracking) { true }
let(:force_exact_time_tracking) { false }
diff --git a/modules/costs/spec/models/work_package_spec.rb b/modules/costs/spec/models/work_package_spec.rb
index a61f2574a7e..4839adee380 100644
--- a/modules/costs/spec/models/work_package_spec.rb
+++ b/modules/costs/spec/models/work_package_spec.rb
@@ -42,7 +42,7 @@ RSpec.describe WorkPackage do
author: user)
end
let!(:cost_entry) do
- create(:cost_entry, work_package:, project:, units: 3, spent_on: Date.today, user:,
+ create(:cost_entry, entity: work_package, project:, units: 3, spent_on: Date.current, user:,
comments: "test entry")
end
let!(:budget) { create(:budget, project:) }