Handle QuickBooks custom fields generically; no vehicle code left

redmine_qbo now works the same for any business; vehicle behaviour lives in redmine_qbo_vehicles.

- Every enabled QuickBooks text custom field gets a box on the estimate/invoice editor (the sales person
  is still filled in automatically). Forms keep custom_fields { field_id => value } instead of vin and
  mileage; Duplicate and Create invoice copy them all.
- Company: custom_field_matching(pattern) and editable_custom_fields; the VIN and Mileage name patterns
  are gone.
- Hooks are keyed by custom field id: qbo_billing_field_options (box suggestions) and
  qbo_billing_field_defaults (values for a document's work orders) replace the VIN hooks;
  qbo_billing_issue_values returns { field_id => { issue_id => value } }.
- Editor script API for plugins: window.qboEditor, the qbo:customer-changed and qbo:imported events, and
  the view_qbo_estimate_form_bottom hook to add a script. The VIN/mileage filling and the several-vehicle
  warning moved to redmine_qbo_vehicles.
- EstimateWriter.create_estimate(custom_fields:), custom_field_value and custom_field_values replace
  the vin/mileage arguments and vin_for.

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 11:34:10 -04:00
1 parent cb705d9525
commit 388ac915d7
14 files changed
+192 -164

No files matched your search

+7 -7
View File
@@ -13,10 +13,10 @@ module RedmineQboBilling
# them:
#
# :qbo_billing_issue_values, { issues: [Issue, ...] }
# Return a hash of field => { issue_id => value }, e.g. redmine_qbo_vehicles returns
# { vin: { 116 => "1C4HJXDG5JW123456" }, mileage: { 116 => "48210" } } (mileage from the issue custom
# field named "Mileage"). The invoice's VIN and mileage boxes are filled from them when time or
# estimates are imported (the highest mileage wins).
# Return a hash of QuickBooks custom field id => { issue_id => value }, e.g. redmine_qbo_vehicles returns
# { "2" => { 116 => "1C4HJXDG5JW123456" } } for the VIN field. They're given to the editor's script with
# imported time and estimates (the qbo:imported event), and to other plugins (e.g. redmine_qbo_lineitems'
# estimates); the plugin's own editor script decides how to fill its fields.
#
# :qbo_billing_validate, { document: "invoice" or "estimate", form: EstimateForm, issues: [Issue, ...] }
# Return an error message (or a list of them) to stop the save, e.g. redmine_qbo_vehicles refuses an
@@ -51,7 +51,7 @@ module RedmineQboBilling
ids.empty? ? [] : Issue.where(id: ids).to_a
end
# { vin: { "116" => "..." }, mileage: { "116" => "..." } } from every plugin listening
# { "2" => { "116" => "..." } } (custom field id => values by issue) from every plugin listening
def values_for(issues)
issues = Array(issues)
return {} if issues.empty?
@@ -60,12 +60,12 @@ module RedmineQboBilling
next unless result.is_a?(Hash)
result.each do |field, by_issue|
next unless by_issue.is_a?(Hash)
(merged[field.to_sym] ||= {}).merge!(by_issue.transform_keys(&:to_s).transform_values(&:to_s).reject { |_, v| v.strip.empty? })
(merged[field.to_s] ||= {}).merge!(by_issue.transform_keys(&:to_s).transform_values(&:to_s).reject { |_, v| v.strip.empty? })
end
end
end
# The same values by issue, for the import panel: { "116" => { vin: "...", mileage: "..." } }
# The same values by issue, for the editor: { "116" => { "2" => "..." } }
def by_issue(issues)
values_for(issues).each_with_object({}) do |(field, by_id), result|
by_id.each { |id, value| (result[id] ||= {})[field] = value }