Use QuickBooks' newer custom fields once estimates show them

QuickBooks keeps listing the legacy sales form fields (DefinitionIds 1-3) in the
preferences after a company moves to its newer custom fields, often renamed or inactive
(e.g. "Sales Rep old"). Once estimates show any newer field, only those are used.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-04 09:47:36 -05:00
1 parent 92b2a18eb6
commit 95e76a41fd
1 file changed
+10 -2
+10 -2
View File
@@ -24,6 +24,8 @@ module RedmineQboBilling
MISSING_FIELD_CACHE_TIME = 5.minutes MISSING_FIELD_CACHE_TIME = 5.minutes
# Recent estimates also show which custom fields exist, for companies whose preferences don't list them # Recent estimates also show which custom fields exist, for companies whose preferences don't list them
RECENT_ESTIMATES = 20 RECENT_ESTIMATES = 20
# QuickBooks' legacy sales form custom fields; its newer custom fields have larger DefinitionIds
LEGACY_FIELD_IDS = (1..3).freeze
# The sales person field is found loosely, e.g. "Sales Person", "Salesperson", "Sales Rep" # The sales person field is found loosely, e.g. "Sales Person", "Salesperson", "Sales Rep"
SALES_PERSON_NAME = /sales|\brep\b/i SALES_PERSON_NAME = /sales|\brep\b/i
@@ -105,9 +107,15 @@ module RedmineQboBilling
nil nil
end end
# Fields named in the preferences come first; fields only seen on estimates are added after them. # QuickBooks' newer custom fields (made under Settings > Custom fields) aren't in the preferences, which
# QuickBooks' newer custom fields (e.g. on Advanced and sandbox companies) may not be in the preferences. # keep listing the legacy fields (DefinitionIds 1-3) after a company moves to the newer ones, often
# renamed or inactive (e.g. "Sales Rep old"). Once estimates show any newer field, those are the
# company's fields and the legacy ones are left out. Otherwise the legacy fields named in the
# preferences come first, then any only seen on estimates.
def merge_fields(from_preferences, from_estimates) def merge_fields(from_preferences, from_estimates)
newer = from_estimates.reject { |f| LEGACY_FIELD_IDS.cover?(f[:id]) }
return newer if newer.any?
ids = from_preferences.map { |f| f[:id] } ids = from_preferences.map { |f| f[:id] }
from_preferences + from_estimates.reject { |f| ids.include?(f[:id]) } from_preferences + from_estimates.reject { |f| ids.include?(f[:id]) }
end end