From 3bbceacda407a5e42e5226e09a282f193ab6504c Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Wed, 4 Nov 2026 12:41:32 -0500 Subject: [PATCH] Don't take the sales person from a retired custom field When an estimate didn't have the company's sales person field, the plugin fell back to any field named like "Sales Rep", e.g. a retired "Sales Rep old" dropdown, which QuickBooks returns as its option number. Invoices made from those estimates got "4" as their sales person. Only the company's field is read now; an estimate without it has no sales person, so the invoice gets the user who creates it. Matching by name is left for when QuickBooks' settings can't be read, and never picks a hidden field. Co-Authored-By: Claude Opus 5.5 --- lib/redmine_qbo_billing/estimate_writer.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/redmine_qbo_billing/estimate_writer.rb b/lib/redmine_qbo_billing/estimate_writer.rb index 4a5aeb8..f557061 100644 --- a/lib/redmine_qbo_billing/estimate_writer.rb +++ b/lib/redmine_qbo_billing/estimate_writer.rb @@ -291,11 +291,17 @@ module RedmineQboBilling # QuickBooks' own subtotal (always after the last line), discount and group lines aren't edited here end - # The custom field's value, found by the field QuickBooks' preferences name, or by name on the estimate + # The custom field's value on a QuickBooks estimate or invoice ("" when it isn't there) def custom_value(remote, field, name_pattern = nil) fields = Array(remote.custom_fields) - match = fields.detect { |f| field && f.id.to_i == field.id.to_i } || - (name_pattern && fields.detect { |f| f.name.to_s =~ name_pattern }) + # The company's field, by id. A document without it has no value: falling back to a similarly named + # field picked up retired ones, e.g. a "Sales Rep old" dropdown, which QuickBooks returns as its option + # number ("4"), and that number was copied onto invoices as the sales person. + return fields.detect { |f| f.id.to_i == field.id.to_i }&.string_value.to_s if field + + # The field isn't known (QuickBooks' settings couldn't be read): found by name, never a hidden one + hidden = Company.hidden_field_ids + match = name_pattern && fields.detect { |f| f.name.to_s =~ name_pattern && !hidden.include?(f.id.to_i) } match&.string_value.to_s end