From 895733f53495385455990aeb5dbf122d710379ac Mon Sep 17 00:00:00 2001
From: Rick Barrette
+ + <%= 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 }