From 895733f53495385455990aeb5dbf122d710379ac Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 4 Nov 2026 10:07:54 -0500 Subject: [PATCH] Let admins hide QuickBooks custom fields from estimates and invoices QuickBooks doesn't tell apps which custom fields are inactive, and a field stays on its old estimates after it's turned off, so an inactive "Sales Rep old" kept showing and was filled in with the sales person. The billing settings now list the fields found, with a box to hide each; hidden fields are left out of the editor, the sales person and other plugins' field lookups. Co-Authored-By: Claude Opus 5.5 --- app/views/qbo/_billing_settings.html.erb | 30 ++++++++++++++++++++++++ config/locales/en.yml | 3 +++ lib/redmine_qbo_billing/company.rb | 17 +++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/app/views/qbo/_billing_settings.html.erb b/app/views/qbo/_billing_settings.html.erb index b507963..fff23c1 100644 --- a/app/views/qbo/_billing_settings.html.erb +++ b/app/views/qbo/_billing_settings.html.erb @@ -16,6 +16,36 @@ multiple: true, size: 8, id: 'settings_labor_item_ids' %> <%= l(:text_labor_items) %>

+ <%# QuickBooks custom fields to leave out of estimates and invoices (see RedmineQboBilling::Company). Hidden + fields that aren't found right now (e.g. no recent estimate has them) are kept as hidden. %> + <% company = RedmineQboBilling::Company %> + <% qbo_fields = company.all_custom_fields %> + <% hidden_ids = company.hidden_field_ids %> + <% sales_field = company.sales_person_field %> +

+ + <%= hidden_field_tag 'settings[hidden_custom_field_ids][]', '', id: nil %> + <% (hidden_ids - qbo_fields.map { |f| f.id.to_i }).each do |id| %> + <%= hidden_field_tag 'settings[hidden_custom_field_ids][]', id, id: nil %> + <% end %> + <% if qbo_fields.empty? %> + <%= l(:label_none) %> + <% else %> + <% qbo_fields.each do |field| %> + + <% end %> + <% end %> + <%= link_to sprite_icon('reload', l(:button_refresh_quickbooks_fields)), refresh_company_qbo_estimates_path, + method: :post, class: 'icon icon-reload' %> + <%= l(:text_qbo_hidden_custom_fields) %> +

<% issue_builder = RedmineQboBilling::EstimateIssueBuilder %> diff --git a/config/locales/en.yml b/config/locales/en.yml index dd1fabc..6fa92d1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -129,6 +129,9 @@ en: button_email_estimate: "Email" button_open_in_quickbooks: "Open in QuickBooks" button_refresh_quickbooks_fields: "Refresh QuickBooks fields" + label_qbo_hidden_custom_fields: "Hide QuickBooks custom fields" + text_qbo_sales_person_field: "filled in with the sales person" + text_qbo_hidden_custom_fields: "Ticked fields are left off estimates and invoices. QuickBooks doesn't tell apps which custom fields are inactive, and a field stays on its old estimates after it's turned off, so tick ones you no longer use (e.g. a renamed \"Sales Rep old\"). The sales person goes in the first field shown whose name has \"sales\" or \"rep\" in it." button_reload_estimate: "Reload the estimate" button_save_and_send: "Save and send" diff --git a/lib/redmine_qbo_billing/company.rb b/lib/redmine_qbo_billing/company.rb index 080c1db..3767bf3 100644 --- a/lib/redmine_qbo_billing/company.rb +++ b/lib/redmine_qbo_billing/company.rb @@ -34,11 +34,26 @@ module RedmineQboBilling module_function - # All enabled sales form custom fields, in QuickBooks' order + # The sales form custom fields the plugin uses, in QuickBooks' order: all those found, except the ones + # hidden in the plugin settings. Everything else (the editor, the sales person, other plugins' VIN and + # mileage) goes through here, so a hidden field is never shown or filled in. def custom_fields + hidden = hidden_field_ids + all_custom_fields.reject { |f| hidden.include?(f.id.to_i) } + end + + # Every custom field found, hidden ones included (listed on the plugin settings page) + def all_custom_fields Array(settings[:custom_fields]).map { |f| Field.new(f[:id], f[:name]) } end + # Fields hidden in the plugin settings. QuickBooks doesn't tell apps which custom fields are inactive, + # and a field stays on its old estimates after it's turned off (e.g. a renamed "Sales Rep old"), so the + # plugin can't leave those out by itself. + def hidden_field_ids + Array((Setting.plugin_redmine_qbo || {})['hidden_custom_field_ids']).map(&:to_i).reject(&:zero?) + end + # The first enabled custom field whose name matches, e.g. a plugin's VIN field (/\bvin\b/i), or nil def custom_field_matching(pattern) custom_fields.detect { |f| f.name.to_s =~ pattern }