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

migrate costs settings to regular settings

Klaus Zanders89c0665af0ad
diff --git a/db/migrate/20241121094113_migrate_cost_settings_to_regular_settings.rb b/db/migrate/20241121094113_migrate_cost_settings_to_regular_settings.rb
new file mode 100644
index 00000000000..7d1c1a4b871
--- /dev/null
+++ b/db/migrate/20241121094113_migrate_cost_settings_to_regular_settings.rb
@@ -0,0 +1,24 @@
+class MigrateCostSettingsToRegularSettings < ActiveRecord::Migration[7.1]
+ def up
+ costs_settings = Setting.plugin_costs || {}
+ if costs_settings["costs_currency"]
+ Setting.create(name: "costs_currency", value: costs_settings["costs_currency"])
+ end
+
+ if costs_settings["costs_currency_format"]
+ Setting.create(name: "costs_currency_format", value: costs_settings["costs_currency_format"])
+ end
+
+ Setting.where(name: "plugin_costs").destroy_all
+ end
+
+ def down
+ costs_settings = {
+ "costs_currency" => Setting.costs_currency,
+ "costs_currency_format" => Setting.costs_currency_format
+ }
+
+ Setting.create(name: "plugin_costs", value: costs_settings)
+ Setting.where(name: ["costs_currency", "costs_currency_format"]).destroy_all
+ end
+end
diff --git a/modules/costs/lib/costs/engine.rb b/modules/costs/lib/costs/engine.rb
index bd17020ba23..4d3d18cb858 100644
--- a/modules/costs/lib/costs/engine.rb
+++ b/modules/costs/lib/costs/engine.rb
@@ -38,11 +38,6 @@ module Costs
author_url: "https://www.openproject.org",
bundled: true,
settings: {
- default: {
- "costs_currency" => "EUR",
- "costs_currency_format" => "%n %u",
- "track_start_and_end_times" => "false"
- },
partial: "settings/costs",
page_title_key: :label_setting_plural,
breadcrumb_elements: -> {
@@ -136,6 +131,12 @@ module Costs
caption: :label_cost_type_plural
end
+ initializer "costs.settings" do
+ ::Settings::Definition.add "costs_currency", default: "EUR", format: :string
+ ::Settings::Definition.add "costs_currency_format", default: "%n %u", format: :string
+ ::Settings::Definition.add "allow_tracking_start_and_end_times", default: false, format: :boolean
+ end
+
initializer "costs.feature_decisions" do
OpenProject::FeatureDecisions.add :track_start_and_end_times_for_time_entries,
description: "Allows admins to enable tracking start and end times for time entries"