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

+1
View File
@@ -222,6 +222,7 @@ Hook|:qbo_billing_issue_values, { issues: } | Return `{ field => { issue_id => v
Hook|:qbo_billing_validate, { document:, form:, issues: } | Return an error message (or several) to stop an estimate or invoice from saving, e.g. redmine_qbo_vehicles: one vehicle per invoice
Hook|:qbo_billing_issue_defaults, { estimate:, params: } | Return `start_date`, `due_date`, `assignee`, `project`, `description`, `return_path`, `return_label`, plus any values your own fields need (e.g. redmine_qbo_calendar's `vehicle_id`), for issues created from an estimate (redmine_qbo_calendar, when opened from an appointment)
Hook|:qbo_billing_build_issue, { issue:, estimate:, defaults: } | Set your plugin's own fields on each issue created from an estimate, before it's saved (redmine_qbo_vehicles sets the vehicle: the one in `defaults`, or the customer's vehicle whose VIN is on the estimate)
View|:view_qbo_estimate_issues_form, { estimate:, defaults:, project: } | Draw your plugin's fields on the Create issues from estimate page, applied to every issue. Name them `issue_plugin_fields[name]`; the posted values reach `:qbo_billing_build_issue` in `defaults` (redmine_qbo_vehicles: the Vehicle, preselected from the estimate's VIN)
Hook|:qbo_billing_issues_created, { estimate:, issues:, params: } | Called after issues are created from an estimate
Hook|:qbo_billing_default_vin, { customer:, issues: } | Return the VIN a new estimate or invoice starts with (an invoice made from an estimate keeps the estimate's VIN; `issues` are that estimate's work orders). redmine_qbo_vehicles: the work orders' vehicle when they share one, else the customer's only vehicle
Hook|:qbo_billing_vin_options, { customer: } | Return `[{ vin:, name: }, ...]` to suggest in the estimate/invoice VIN box; one suggestion fills an empty box (redmine_qbo_vehicles: the customer's vehicles)
+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)
@@ -136,12 +136,15 @@
</tbody>
</table>
<%# Custom fields for the chosen trackers, entered once and applied to every issue that uses them %>
<% if @field_set&.any? %>
<%# Fields entered once and applied to every issue: plugins' own (e.g. redmine_qbo_vehicles' vehicle, posted as
issue_plugin_fields[...]) and the custom fields for the chosen trackers %>
<% plugin_fields = call_hook(:view_qbo_estimate_issues_form, { estimate: @estimate, defaults: @defaults, project: @target_project }) %>
<% if @field_set&.any? || plugin_fields.present? %>
<fieldset class="box tabular estimate-issue-fields" id="estimate-issue-fields">
<legend><%= l(:label_estimate_issue_fields) %></legend>
<p class="estimate-issue-fields-info"><em class="info"><%= l(:text_estimate_issue_fields_info) %></em></p>
<% @field_set.fields.each do |field| %>
<%= plugin_fields %>
<% Array(@field_set&.fields).each do |field| %>
<p class="estimate-issue-field"
data-tracker-ids="<%= field.tracker_ids.join(',') %>"
data-required-tracker-ids="<%= field.required_tracker_ids.join(',') %>">
@@ -24,6 +24,9 @@ module RedmineQboBilling
# redmine_qbo_calendar's vehicle_id, when the page is opened from an appointment)
# :qbo_billing_build_issue, { issue:, estimate:, defaults: } for each new issue before it's saved, to set
# plugins' own fields (e.g. redmine_qbo_vehicles sets the vehicle)
# :view_qbo_estimate_issues_form, { estimate:, defaults:, project: } (view hook) draws plugins' fields on
# the page, applied to every issue; posted as issue_plugin_fields[name], they reach :qbo_billing_build_issue
# in defaults (e.g. redmine_qbo_vehicles' Vehicle, preselected from the estimate's VIN)
# :qbo_billing_issues_created, { estimate:, issues:, params: } after issues are created
class EstimateIssueBuilder
include Redmine::I18n