mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-18 02:20:37 -05:00
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:
5 files changed
+40
-20
No files matched your search
@@ -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) }
|
||||
|
||||
@@ -47,7 +47,6 @@ module RedmineQboBilling
|
||||
customer_name: customer&.name,
|
||||
email: writer.customer_email(customer),
|
||||
billing_address: writer.customer_address(customer),
|
||||
vin: RedmineQboBilling.default_vin(customer),
|
||||
txn_date: user.today.iso8601,
|
||||
sales_person: user.name,
|
||||
customer_memo: Company.invoice_message,
|
||||
@@ -73,8 +72,7 @@ module RedmineQboBilling
|
||||
form.billing_address = source.billing_address.presence || form.billing_address
|
||||
# The estimate's VIN, or else a plugin's for the estimate's work orders (e.g. their vehicle)
|
||||
form.vin = source.vin.presence ||
|
||||
RedmineQboBilling.default_vin(customer, issues: Issue.where(estimate_id: source.id.to_s).to_a) ||
|
||||
form.vin
|
||||
RedmineQboBilling.default_vin(customer, issues: Issue.where(estimate_id: source.id.to_s).to_a)
|
||||
form.mileage = source.mileage
|
||||
# The estimate's writer sells the job; with no one on the estimate, whoever writes the invoice
|
||||
form.sales_person = source.sales_person.presence || user.name
|
||||
@@ -363,6 +361,8 @@ module RedmineQboBilling
|
||||
issue: linked_issue&.then { |i| "#{i.tracker} ##{i.id}: #{i.subject}" },
|
||||
# Lines from this estimate go next to the invoice's time for the same issue
|
||||
issue_id: issue_reference(lines.detect { |l| l.description.present? }&.description) || linked_issue&.id&.to_s,
|
||||
# The estimate's own VIN, used when its work orders give none
|
||||
vin: writer.custom_value(e, Company.vin_field, Company::VIN_NAME).to_s.strip,
|
||||
lines: lines.map { |l| line_hash(l) }
|
||||
}
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user