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 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-04 12:41:32 -05:00
1 parent d75dee2866
commit 3bbceacda4
1 file changed
+9 -3
+9 -3
View File
@@ -291,11 +291,17 @@ module RedmineQboBilling
# QuickBooks' own subtotal (always after the last line), discount and group lines aren't edited here # QuickBooks' own subtotal (always after the last line), discount and group lines aren't edited here
end 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) def custom_value(remote, field, name_pattern = nil)
fields = Array(remote.custom_fields) fields = Array(remote.custom_fields)
match = fields.detect { |f| field && f.id.to_i == field.id.to_i } || # The company's field, by id. A document without it has no value: falling back to a similarly named
(name_pattern && fields.detect { |f| f.name.to_s =~ name_pattern }) # 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 match&.string_value.to_s
end end