Vehicle picker on the Create issues from estimate page

redmine_qbo's Create issues page gets a Vehicle for all the issues (view hook
view_qbo_estimate_issues_form): preselected with the appointment's vehicle, else the customer's vehicle
matching the estimate's VIN. When none matches, or the estimate has no VIN, it says so, so the team can
pick one first. The chosen vehicle (or none) is what qbo_billing_build_issue puts on the issues.

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:25:02 -04:00
1 parent 14abda2022
commit d987746c40
6 files changed
+81 -18

No files matched your search

+5 -17
View File
@@ -50,13 +50,15 @@ module Vehicles
with_vin.first.vin if with_vin.size == 1
end
# Issues created from an estimate get a vehicle: the one passed in (e.g. redmine_qbo_calendar's
# appointment vehicle), or the customer's vehicle whose VIN is on the estimate
# Issues created from an estimate get a vehicle: the one picked on the Create issues page (or passed in,
# e.g. redmine_qbo_calendar's appointment vehicle; blank means none), else the customer's vehicle whose
# VIN is on the estimate
def qbo_billing_build_issue(context = {})
issue = context[:issue]
return unless issue.respond_to?(:vehicle_id=)
vehicle_id = context.dig(:defaults, :vehicle_id).presence || vehicle_id_from_vin(context[:estimate])
defaults = (context[:defaults] || {}).to_h.symbolize_keys
vehicle_id = defaults.key?(:vehicle_id) ? defaults[:vehicle_id].presence : Vehicles::EstimateVehicle.match(context[:estimate])&.id
issue.vehicle_id = vehicle_id if vehicle_id
end
@@ -77,20 +79,6 @@ module Vehicles
private
# The customer's vehicle whose VIN is on the estimate's QuickBooks VIN field, or nil
def vehicle_id_from_vin(estimate)
customer = estimate&.customer
return nil unless customer.respond_to?(:vehicles)
company = RedmineQboBilling::Company
vin = RedmineQboBilling::EstimateWriter.custom_value(estimate.details, company.vin_field, company::VIN_NAME).to_s.strip
return nil if vin.empty?
customer.vehicles.detect { |v| v.vin.to_s.casecmp?(vin) }&.id
rescue StandardError
nil
end
# { issue_id => mileage } from the issue custom field named "Mileage"; empty without that field
def mileage_by_issue(issues)
issue_ids = issues.map(&:id)
+9
View File
@@ -20,6 +20,15 @@ module Vehicles
])
end
# redmine_qbo's Create issues from estimate page: a Vehicle for all the issues, preselected from the
# estimate's VIN
def view_qbo_estimate_issues_form(context = {})
return '' unless context[:estimate]
context[:hook_caller].render(partial: 'vehicles/estimate_issues_vehicle',
locals: { estimate: context[:estimate], defaults: context[:defaults] })
end
end
end
end