Let plugins add fields to the Create issues from estimate page

View hook view_qbo_estimate_issues_form draws plugins' fields in the shared Issue fields box; values
posted as issue_plugin_fields[name] override the plugin defaults and reach qbo_billing_build_issue.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-10-31 10:25:03 -04:00
1 parent b84f39afce
commit abeb0fe0f5
4 files changed
+21 -4

No files matched your search

+11 -1
View File
@@ -155,7 +155,8 @@ class QboEstimatesController < ApplicationController
end
return render_404 unless @estimate
@defaults = issue_defaults
# Values plugins' fields posted with the form (e.g. redmine_qbo_vehicles' vehicle) override their defaults
@defaults = issue_defaults.merge(submitted_plugin_fields)
@builder = RedmineQboBilling::EstimateIssueBuilder.new(@estimate, defaults: @defaults)
@return_path = @defaults[:return_path].presence || edit_qbo_estimate_path(@estimate.id)
@return_label = @defaults[:return_label].presence || "#{l(:label_estimate)} ##{@estimate.doc_number}"
@@ -185,6 +186,15 @@ class QboEstimatesController < ApplicationController
(results.detect { |r| r.is_a?(Hash) && r.any? } || {}).symbolize_keys
end
# Plugins' own fields on the preview form (issue_plugin_fields[...], drawn by :view_qbo_estimate_issues_form),
# only when the form was posted: { vehicle_id: "5" }
def submitted_plugin_fields
return {} unless request.post?
values = params[:issue_plugin_fields]
values.respond_to?(:to_unsafe_h) ? values.to_unsafe_h.to_h.transform_keys(&:to_sym).transform_values(&:to_s) : {}
end
# The shared custom field values from the preview form: { custom_field_id => value }
def submitted_custom_field_values
values = params.dig(:issue, :custom_field_values)