Blank VIN on new documents; VIN from attached estimates; read estimate VINs with newer custom fields

- New estimates and invoices start with a blank VIN; picking a customer only fills the VIN box's
  suggestions.
- Importing an estimate whose work orders give no VIN fills the invoice's VIN box with the estimate's
  own VIN (open estimates now carry it).
- EstimateWriter.vin_for reads an estimate's VIN with QuickBooks' newer custom fields (cached a minute).
  The local Estimate's details leave those out, so plugins matching the estimate's VIN to a vehicle
  never found one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-10-31 10:52:39 -04:00
1 parent abeb0fe0f5
commit cb705d9525
5 files changed
+40 -20

No files matched your search

+14 -1
View File
@@ -36,7 +36,6 @@ module RedmineQboBilling
customer_name: customer&.name,
email: customer_email(customer),
billing_address: customer_address(customer),
vin: RedmineQboBilling.default_vin(customer),
txn_date: user.today.iso8601,
expiration_date: default_expiration_date(user.today)&.iso8601,
sales_person: user.name,
@@ -143,6 +142,20 @@ module RedmineQboBilling
saved
end
# The VIN on an estimate, read with QuickBooks' newer custom fields (a plain fetch, e.g. Estimate#details,
# leaves them out). Cached for a minute, since creating issues asks once per issue.
def vin_for(estimate_id)
return nil if estimate_id.blank?
Rails.cache.fetch("redmine_qbo:estimate_vin:#{estimate_id}", expires_in: 1.minute) do
remote = QboEstimateService.with_service { |service| service.fetch_by_id(estimate_id) }
remote ? custom_value(remote, Company.vin_field, Company::VIN_NAME).to_s.strip : ''
end.presence
rescue StandardError => e
Rails.logger.warn "[RedmineQboBilling] Could not read estimate #{estimate_id}'s VIN: #{e.message}"
nil
end
# Emails the estimate; QuickBooks uses its own estimate email template
def send_email(id, email)
sent = QboEstimateService.with_service { |service| service.send_estimate(id, email) }