From 91caa51ab7b017277bf8fdeca97f7338b74b88bc Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 28 Oct 2026 21:08:58 -0400 Subject: [PATCH] Add a default project setting for issues created from estimates Redmine has no default-project setting for new issues, so the preview page used the first project the user could add issues to whenever an appointment had no project. The plugin settings now have a Default project; the order is: project chosen on the page, the appointment's project, the default project, then the first allowed project. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM --- app/controllers/customer_appointments_controller.rb | 6 ++++-- app/views/settings/_qbo_calendar_settings.html.erb | 9 +++++++++ config/locales/en.yml | 2 ++ init.rb | 2 +- lib/redmine_qbo_calendar/estimate_issue_builder.rb | 4 ++++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/controllers/customer_appointments_controller.rb b/app/controllers/customer_appointments_controller.rb index 03380e8..4b83101 100644 --- a/app/controllers/customer_appointments_controller.rb +++ b/app/controllers/customer_appointments_controller.rb @@ -160,14 +160,16 @@ class CustomerAppointmentsController < ApplicationController @builder = RedmineQboCalendar::EstimateIssueBuilder.new(@appointment) @available_projects = Project.allowed_to(User.current, :add_issues).sorted.to_a - # A project chosen on the page wins, then the appointment's project, then the first allowed one + # A project chosen on the page wins, then the appointment's project, then the default project + # from the plugin settings, then the first project the user can add issues to + default_project = @available_projects.detect { |p| p.id == RedmineQboCalendar::EstimateIssueBuilder.default_project_id } @target_project = if @project @project if @available_projects.include?(@project) elsif @available_projects.include?(@appointment.project) @appointment.project else - @available_projects.first + default_project || @available_projects.first end return deny_access unless @target_project diff --git a/app/views/settings/_qbo_calendar_settings.html.erb b/app/views/settings/_qbo_calendar_settings.html.erb index 6235c6c..2f59ac0 100644 --- a/app/views/settings/_qbo_calendar_settings.html.erb +++ b/app/views/settings/_qbo_calendar_settings.html.erb @@ -7,6 +7,15 @@ <%= l(:text_estimate_item_codes_info) %>

+

+ + <%= select_tag 'settings[default_project_id]', + project_tree_options_for_select(Project.active.sorted, + selected: Project.find_by(id: settings['default_project_id'].to_i)), + include_blank: true, id: 'settings_default_project_id' %> + <%= l(:text_default_project_info) %> +

+

<%= select_tag 'settings[default_tracker_id]', diff --git a/config/locales/en.yml b/config/locales/en.yml index e31ca5f..2182860 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -60,6 +60,7 @@ en: label_edit_appointment: Edit Appointment label_end_date: End Date label_estimated_hours: Estimated Time + label_default_project: "Default project" label_default_tracker: "Default tracker" label_estimate_issue_settings: "Issues from estimates" label_estimate_issue_fields: "Issue fields" @@ -102,6 +103,7 @@ en: permission_edit_customer_appointments: "Edit customer appointments" permission_manage_customer_appointments: Manage Customer Appointments permission_view_customer_appointments: "View customer appointments" + text_default_project_info: "Where issues from estimates are created when the appointment has no project. Users who can't add issues there get their first allowed project. It can still be changed on the preview page." text_default_tracker_info: "Pre-selected for each proposed issue. Leave blank to use the project's first tracker." text_estimate_issue_fields_info: "Entered once and applied to every created issue whose tracker uses the field. Fields marked * are required by the selected trackers." text_estimate_issues_hint: "The subject comes from the estimate line's description and estimated hours from its quantity. Edit anything before creating. New issues are related to each other and to issues already created from this estimate." diff --git a/init.rb b/init.rb index 98be3d2..1c8f28a 100644 --- a/init.rb +++ b/init.rb @@ -20,7 +20,7 @@ Redmine::Plugin.register :redmine_qbo_calendar do requires_redmine version_or_higher: '7.0.0' # Item codes: which QBO estimate items can become issues (e.g. Labor, Alignments) - settings default: { 'item_codes' => "Labor", 'default_tracker_id' => '' }, + settings default: { 'item_codes' => "Labor", 'default_tracker_id' => '', 'default_project_id' => '' }, partial: 'settings/qbo_calendar_settings' # Add Holidays index to the Redmine Administration Menu diff --git a/lib/redmine_qbo_calendar/estimate_issue_builder.rb b/lib/redmine_qbo_calendar/estimate_issue_builder.rb index 756f6ed..a3b98fb 100644 --- a/lib/redmine_qbo_calendar/estimate_issue_builder.rb +++ b/lib/redmine_qbo_calendar/estimate_issue_builder.rb @@ -39,6 +39,10 @@ module RedmineQboCalendar settings['default_tracker_id'].to_i end + def self.default_project_id + settings['default_project_id'].to_i + end + def self.settings Setting.plugin_redmine_qbo_calendar || {} rescue StandardError