mirror of
https://github.com/rickbarrette/redmine_qbo_vehicles.git
synced 2026-11-17 18:40:36 -05:00
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:
6 files changed
+81
-18
No files matched your search
@@ -19,7 +19,7 @@ The goal of this project is to enable vehicle tracking for customer vehicles wit
|
||||
* **Asset Tracking:** Adds vehicles owned by customers to the system.
|
||||
* **Issue Association:** Allows these vehicles to be attached directly to Redmine issues for better service tracking.
|
||||
* **Invoices (redmine_qbo 2026.11.0+):** importing a work order's time or estimate fills the invoice's VIN box with its vehicle's VIN and the mileage box with the highest value of the work orders' **Mileage** issue custom field (Redmine's own custom field named "Mileage"), and an invoice whose work orders are for more than one vehicle isn't saved (one vehicle per invoice).
|
||||
* **Estimates (redmine_qbo 2026.11.0+):** the VIN box suggests the customer's vehicles, and a new estimate or invoice starts with the VIN of its work orders' vehicle (or of the customer's only vehicle), and issues created from an estimate get the appointment's vehicle, or else the customer's vehicle whose VIN is on the estimate.
|
||||
* **Estimates (redmine_qbo 2026.11.0+):** the VIN box suggests the customer's vehicles, and a new estimate or invoice starts with the VIN of its work orders' vehicle (or of the customer's only vehicle), and the Create issues from estimate page has a **Vehicle** for all the issues: preselected with the appointment's vehicle, or else the customer's vehicle whose VIN is on the estimate; when none matches it says so, so the team can pick one before creating the issues.
|
||||
* **Customer page:** ticking a vehicle adds it to the New issue link.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
<%#
|
||||
Vehicle for the issues created from an estimate (redmine_qbo's Create issues page). Preselected: the vehicle
|
||||
already picked (or passed in, e.g. an appointment's), else the customer's vehicle matching the estimate's VIN.
|
||||
Posted as issue_plugin_fields[vehicle_id]; see Vehicles::Hooks::BillingHookListener#qbo_billing_build_issue.
|
||||
%>
|
||||
<%
|
||||
estimate_vin = Vehicles::EstimateVehicle.vin(estimate)
|
||||
matched = Vehicles::EstimateVehicle.match(estimate, estimate_vin)
|
||||
vehicles = Vehicles::EstimateVehicle.vehicles(estimate)
|
||||
defaults = (defaults || {}).to_h.symbolize_keys
|
||||
selected = defaults.key?(:vehicle_id) ? defaults[:vehicle_id].to_s : matched&.id.to_s
|
||||
%>
|
||||
<p class="estimate-issue-field estimate-issue-vehicle">
|
||||
<label for="estimate_issue_vehicle_id"><%= l(:field_vehicle) %></label>
|
||||
<%= select_tag 'issue_plugin_fields[vehicle_id]',
|
||||
options_for_select(vehicles.map { |v| [v.vin.present? ? "#{v} (#{v.vin})" : v.to_s, v.id.to_s] }, selected),
|
||||
include_blank: true, id: 'estimate_issue_vehicle_id' %>
|
||||
<% if matched && selected == matched.id.to_s %>
|
||||
<em class="info"><%= l(:text_estimate_vehicle_matched, vin: estimate_vin) %></em>
|
||||
<% elsif estimate_vin && !matched %>
|
||||
<em class="info estimate-vehicle-unmatched" style="color: #b06d00;"><%= l(:text_estimate_vehicle_unmatched, vin: estimate_vin) %></em>
|
||||
<% elsif !estimate_vin %>
|
||||
<em class="info"><%= l(:text_estimate_vehicle_no_vin) %></em>
|
||||
<% end %>
|
||||
</p>
|
||||
@@ -34,6 +34,9 @@ en:
|
||||
label_search_vehicles: "Search Vehicles"
|
||||
label_unknown: "Unknown"
|
||||
label_vehicle: "Vehicle"
|
||||
text_estimate_vehicle_matched: "Matches the estimate's VIN (%{vin})."
|
||||
text_estimate_vehicle_unmatched: "None of the customer's vehicles has the estimate's VIN (%{vin}). Pick the vehicle for these issues, or add it to the customer first."
|
||||
text_estimate_vehicle_no_vin: "The estimate has no VIN. Pick the vehicle for these issues."
|
||||
label_year: "Year"
|
||||
no_customer: "Customer no longer exists"
|
||||
notice_decoding_vin: "Decoding VIN… this page will update automatically."
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#The MIT License (MIT)
|
||||
#
|
||||
#Copyright (c) 2026 rick barrette
|
||||
#
|
||||
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
#
|
||||
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
#
|
||||
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
|
||||
module Vehicles
|
||||
# The customer's vehicle that matches an estimate's VIN (redmine_qbo's QuickBooks VIN field)
|
||||
module EstimateVehicle
|
||||
module_function
|
||||
|
||||
# The VIN on the estimate, or nil
|
||||
def vin(estimate)
|
||||
company = RedmineQboBilling::Company
|
||||
RedmineQboBilling::EstimateWriter.custom_value(estimate.details, company.vin_field, company::VIN_NAME).to_s.strip.presence
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
|
||||
# The customer's vehicles, for picking one
|
||||
def vehicles(estimate)
|
||||
customer = estimate&.customer
|
||||
customer.respond_to?(:vehicles) ? customer.vehicles.to_a : []
|
||||
end
|
||||
|
||||
# The customer's vehicle whose VIN is on the estimate, or nil
|
||||
def match(estimate, estimate_vin = vin(estimate))
|
||||
return nil if estimate_vin.blank?
|
||||
|
||||
vehicles(estimate).detect { |v| v.vin.to_s.strip.casecmp?(estimate_vin) }
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user