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 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-04 10:07:54 -05:00
1 parent fa1b4eed06
commit 895733f534
3 files changed
+49 -1

No files matched your search

+30
View File
@@ -16,6 +16,36 @@
multiple: true, size: 8, id: 'settings_labor_item_ids' %> multiple: true, size: 8, id: 'settings_labor_item_ids' %>
<em class="info"><%= l(:text_labor_items) %></em> <em class="info"><%= l(:text_labor_items) %></em>
</p> </p>
<%# 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 %>
<p class="qbo-custom-fields-setting">
<label><%= l(:label_qbo_hidden_custom_fields) %></label>
<%= 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| %>
<label class="block">
<%= check_box_tag 'settings[hidden_custom_field_ids][]', field.id, hidden_ids.include?(field.id.to_i),
id: "settings_hidden_custom_field_#{field.id}" %>
<%= field.name %>
<% if sales_field && sales_field.id.to_i == field.id.to_i %>
<em>(<%= l(:text_qbo_sales_person_field) %>)</em>
<% end %>
</label>
<% end %>
<% end %>
<%= link_to sprite_icon('reload', l(:button_refresh_quickbooks_fields)), refresh_company_qbo_estimates_path,
method: :post, class: 'icon icon-reload' %>
<em class="info"><%= l(:text_qbo_hidden_custom_fields) %></em>
</p>
</div> </div>
<% issue_builder = RedmineQboBilling::EstimateIssueBuilder %> <% issue_builder = RedmineQboBilling::EstimateIssueBuilder %>
+3
View File
@@ -129,6 +129,9 @@ en:
button_email_estimate: "Email" button_email_estimate: "Email"
button_open_in_quickbooks: "Open in QuickBooks" button_open_in_quickbooks: "Open in QuickBooks"
button_refresh_quickbooks_fields: "Refresh QuickBooks fields" 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_reload_estimate: "Reload the estimate"
button_save_and_send: "Save and send" button_save_and_send: "Save and send"
+16 -1
View File
@@ -34,11 +34,26 @@ module RedmineQboBilling
module_function 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 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]) } Array(settings[:custom_fields]).map { |f| Field.new(f[:id], f[:name]) }
end 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 # 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) def custom_field_matching(pattern)
custom_fields.detect { |f| f.name.to_s =~ pattern } custom_fields.detect { |f| f.name.to_s =~ pattern }