58 Commits

Author SHA1 Message Date
89dc3cd5f4 moved vin decoding into a job 2026-03-25 22:30:02 -04:00
030340b35e 2026.3.2 2026-03-22 14:28:04 -04:00
097276e558 Updated patches and hooks 2026-03-21 12:23:23 -04:00
ea73878c71 renamed issue_customer_id to customer_id 2026-03-19 18:07:36 -04:00
8ec60c8cd7 updated to new autocomplete 2026-03-19 10:20:50 -04:00
9cb38cfbb1 updaed readme 2026-03-07 13:29:13 -05:00
9a1678d353 2026.3.0 2026-03-04 21:00:43 -05:00
28957c5dff fixed eager loading issue 2026-03-04 20:57:29 -05:00
a67b75671e updated logging with prefix 2026-03-04 20:57:12 -05:00
492ff000bf Don't copy the text Copied! 2026-02-26 13:26:45 -05:00
e0fc07141c 2026.2.8 2026-02-25 22:13:18 -05:00
3e6c2672e0 removed duplicate comment 2026-02-25 22:12:48 -05:00
71bde3a249 Enhance search_result_ranks_and_ids method to rank results by ID and streamline query handling 2026-02-25 22:12:14 -05:00
4f2ae19460 2026.2.7 2026-02-22 19:13:20 -05:00
9ee792cbd8 Refactor vehicle model: streamline search functionality using built in modules 2026-02-22 13:19:28 -05:00
ae7ccbf4b0 display VIN & Customer on search event_description 2026-02-21 19:20:28 -05:00
550601b5c9 Merge branch 'dev' 2026-02-21 19:09:29 -05:00
85cd02b16a 2026.2.6 2026-02-21 19:07:06 -05:00
4b8b3c3495 Update search form ID for consistency 2026-02-21 19:06:23 -05:00
b2c1bebea3 show_checkbox: true 2026-02-21 14:07:03 -05:00
2bd13a819b Removed unneeded BR 2026-02-21 14:00:34 -05:00
d6138843f8 Started to extend redmine's search 2026-02-21 09:22:04 -05:00
452568e8b3 fixed search label 2026-02-21 08:45:42 -05:00
a709fecd0c 2026.2.5 2026-02-21 08:34:33 -05:00
6db87dd551 search for a vehicle by vin, make, model, or year, plus sql sanitization 2026-02-21 08:33:59 -05:00
a73b6cd438 2026.2.4 2026-02-20 19:48:55 -05:00
f163f6518b Use DIV and not A for vin element 2026-02-20 19:46:55 -05:00
a89f9881a6 added show_customer and show_checkbox options to vehicle list 2026-02-16 22:01:31 -05:00
ed38584ab2 updated js to copy clicked link text. Also don't need id tags any more. 2026-02-16 21:32:00 -05:00
dba8381913 2026.2.3 2026-02-14 18:56:22 -05:00
d4fa314011 moved screenshot folder 2026-02-14 09:40:46 -05:00
be2effb1b4 Added screenshots 2026-02-14 09:36:52 -05:00
4bcccbd2f1 Fixed formatting, missing </b> 2026-02-13 22:31:59 -05:00
92cc7222fb feat(i18n): sort en.yml and fix typos
Alphabetized keys for better maintainability.

Fixed spelling errors in customer and vehicle keys/values.

Corrected "QuickBooks Online" branding.
2026-02-13 22:25:43 -05:00
c5318a3528 Copied message in bold 2026-02-13 22:06:32 -05:00
9315433cb1 Keep the last 8 bold 2026-02-13 21:50:38 -05:00
82e25314f3 removed unused spans 2026-02-13 21:38:34 -05:00
5cad4a6856 added js to copy vin on click 2026-02-13 21:28:45 -05:00
12fb8b47ef 2026.2.2 2026-02-13 08:01:39 -05:00
b02a40827d Added flash notification for deleted customers. 2026-02-13 08:01:02 -05:00
5165bc20b4 Changed display format of vehicle lists 2026-02-13 07:48:36 -05:00
f30d735e52 2026.2.1 2026-02-11 19:45:08 -05:00
a30d8f56d8 added nil check for customer (if a customer is deleted after a merge) 2026-02-11 19:43:52 -05:00
d22fcd4f66 2026.2.0 2026-02-09 21:52:40 -05:00
f649d4e902 added checkbox for appointment link javascript 2026-02-09 21:44:23 -05:00
2db17f3675 Fixed display of vehcile notes 2026-02-05 14:07:24 -05:00
d37933fe82 2026.1.7
Added vehicle estimates & invoices to vehicle page
2026-01-31 13:00:19 -05:00
3efc545f0a Compact to remove nil elements from the array 2026-01-31 12:55:47 -05:00
adcc116841 Add estimates and invoices sections to vehicle details view 2026-01-31 12:46:41 -05:00
8bb98d2408 Add methods to retrieve invoices and estimates for vehicles 2026-01-31 12:46:30 -05:00
88b0ffcd6b Updaed readme 2026-01-31 08:00:19 -05:00
48deb3b7c8 2026.1.6 2026-01-30 21:32:56 -05:00
e2ea22afdf Removed unused folders 2026-01-30 20:53:46 -05:00
717a61b024 Updated flash notices to use locale 2026-01-30 19:49:48 -05:00
a932551b96 2026.1.5 2026-01-30 17:08:39 -05:00
e09990cd42 added nil check 2026-01-30 17:04:23 -05:00
ad8aa8e2e8 use locale 2026-01-30 08:07:11 -05:00
707abc00a9 Use symbols 2026-01-30 08:05:57 -05:00
33 changed files with 517 additions and 181 deletions

View File

@@ -1,53 +1,54 @@
# Redmine QuickBooks Online Vehicles
A redmine plugin to compliment the Redmine QuickBooks Online Vehicles plug in.
A Redmine plugin to complement the [Redmine QuickBooks Online](https://github.com/rickbarrette/redmine_qbo) plugin.
The goal of this project is to allow add vehicle tracking for customer vehicles.
The goal of this project is to enable vehicle tracking for customer vehicles within Redmine.
## Requirements
* **Redmine:** 6.1+
* **Parent Plugin:** [Redmine QuickBooks Online](https://github.com/rickbarrette/redmine_qbo)
## Compatibility
| Redmine QBO Plugin Version | Redmine Version |
| :--- | :--- |
| Version 2026.1.2+ | Redmine 6.1 |
| Plugin Version | Redmine Version | Ruby Version |
| :--- | :--- | :--- |
| 2026.1.2+ | Redmine 6.1 | 3.2+ |
## Features
Adds vehicles that are owned by customers that can be attached to issues.
* **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.
## Installation
1. **Clone the plugin:**
Clone this repo into your plugin folder and checkout a tagged version.
Navigate to your Redmine plugins directory and clone the repository.
```bash
cd path/to/redmine/plugins
git clone git@github.com:rickbarrette/redmine_qbo_vehicles.git
cd redmine_qbo_vehicles
git checkout <tag>
```
*(Note: Replace `<tag>` with the specific release version you wish to use, or omit the last line to use the main branch.)*
2. **Install dependencies:** *Crucial for Redmine 6 / Rails 7 compatibility.*
Bash
```
2. **Install dependencies:**
*Crucial for Redmine 6 / Rails 7 compatibility.*
```bash
bundle install
```
3. **Migrate your database:**
Bash
```
```bash
bundle exec rake redmine:plugins:migrate RAILS_ENV=production
```
4. **Restart Redmine:** You must restart your Redmine server instance for the plugin and hooks to load.
4. **Restart Redmine:**
You must restart your Redmine server instance (e.g., Puma, Passenger, Unicorn) for the plugin and hooks to load correctly.
## Usage
Simply add vehicles to customers via Customer Profile
Once a customer is attached to the customer, they can be attached to an issue.
1. **Add a Vehicle:** Navigate to a Customer Profile. You will see a new option to add vehicles to that customer.
2. **Link to Issue:** Once a vehicle is added to a customer, it can be selected and attached to an Issue relevant to that customer.
## License

View File

@@ -25,6 +25,7 @@ class VehiclesController < ApplicationController
begin
@vehicles = Customer.find_by_id(params[:customer_id]).vehicles.paginate(page: params[:page])
rescue ActiveRecord::RecordNotFound
flash[:error] = t :alert_vehicle_not_found
render_404
end
end
@@ -48,7 +49,7 @@ class VehiclesController < ApplicationController
def create
@vehicle = Vehicle.new(allowed_params)
if @vehicle.save
flash[:notice] = "New Vehicle Created"
flash[:notice] = t :notice_vehicle_created
redirect_to @vehicle
else
flash[:error] = @vehicle.errors.full_messages.to_sentence
@@ -59,21 +60,36 @@ class VehiclesController < ApplicationController
# display a specific vehicle
def show
begin
@vehicle = Vehicle.find_by_id(params[:id])
@vehicle = Vehicle.includes(issues: [:estimate, :invoices]).find(params[:id])
@vin = @vehicle.vin.scan(/.{1,9}/) if @vehicle.vin
@issues = @vehicle.issues.order(id: :desc)
@closed_issues = (@issues - @issues.open)
@issues = @vehicle.issues
.joins(:status)
.includes(:estimate, :invoices, :status, :project, :tracker, :priority)
.order(id: :desc)
@open_issues = @issues.select { |i| !i.status.is_closed }
@closed_issues = @issues.select { |i| i.status.is_closed }
flash[:error] = t :alert_no_customer if @vehicle.customer.nil?
rescue
flash[:error] = t :alert_vehicle_not_found
render_404
end
end
def status
vehicle = Vehicle.find(params[:id])
render json: {
decoded: vehicle.vin_decoded
}
end
# return an HTML form for editing a vehicle
def edit
begin
@vehicle = Vehicle.find_by_id(params[:id])
@customer = @vehicle.customer
rescue
flash[:error] = t :alert_vehicle_not_found
render_404
end
end
@@ -84,7 +100,7 @@ class VehiclesController < ApplicationController
begin
@vehicle = Vehicle.find_by_id(params[:id])
if @vehicle.update(allowed_params)
flash[:notice] = "Vehicle updated"
flash[:notice] = t :notice_vehicle_updated
redirect_to @vehicle
else
redirect_to edit_vehicle_path
@@ -92,6 +108,7 @@ class VehiclesController < ApplicationController
#show any errors anyways
flash[:error] = @vehicle.errors.full_messages.to_sentence unless @vehicle.errors.empty?
rescue
flash[:error] = t :alert_vehicle_not_updated
render_404
end
end
@@ -100,9 +117,10 @@ class VehiclesController < ApplicationController
def destroy
begin
Vehicle.find_by_id(params[:id]).destroy
flash[:notice] = "Vehicle deleted successfully"
flash[:notice] = t :notice_vehicle_deleted
redirect_to action: :index
rescue
flash[:error] = t :alert_vehicle_not_deleted
render_404
end
end

View File

@@ -0,0 +1,45 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 - 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.
class VehicleVinDecodeJob < ApplicationJob
queue_as :default
retry_on StandardError, wait: 5.minutes, attempts: 5
def perform(vehicle_id)
log "Looking up VIN for vehicle ##{vehicle_id}"
vehicle = Vehicle.find_by(id: vehicle_id)
return unless vehicle&.vin.present?
result = VinDecoder.call(vehicle.vin)
unless result.success?
log "Failed to decode vin"
vehicle.update(vin_decoded: false)
return
end
details = result.data
vehicle.update(
year: details.year.presence || vehicle.year,
make: details.make.presence || vehicle.make,
model: details.model.presence || vehicle.model,
doors: details.doors.presence || vehicle.doors,
trim: details.trim.presence || vehicle.trim,
name: vehicle.to_s,
vin_decoded: true
)
end
private
def log(msg)
Rails.logger.info "[VehicleVinDecodeJob] #{msg}"
end
end

View File

@@ -8,88 +8,80 @@
#
#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.
class Vehicle < ActiveRecord::Base
class Vehicle < ApplicationRecord
include Redmine::Acts::Searchable
include Redmine::Acts::Event
belongs_to :customer
has_many :issues
validates_presence_of :customer
validates :vin, uniqueness: true
before_save :decode_vin
validates :customer, presence: true
validates :vin, presence: true, uniqueness: true
before_validation :normalize_vin
after_commit :enqueue_vin_decode
acts_as_searchable columns: %w[vin make model year], scope: ->(_context) { all }, date_column: :updated_at
acts_as_event :title => Proc.new {|o| "#{o.to_s}"},
:url => Proc.new {|o| { :controller => 'vehicles', :action => 'show', :id => o.id} },
:type => :to_s,
:description => Proc.new {|o| "#{o.vin} - #{o.customer}"},
:datetime => Proc.new {|o| o.updated_at || o.created_at}
# returns a human readable string
def to_s
if year.nil? or make.nil? or model.nil?
return "#{vin}"
else
split_vin = vin.scan(/.{1,9}/)
return "#{year} #{make} #{model} - #{split_vin[1]}"
end
def estimates
issues.includes(:estimate).flat_map(&:estimate).uniq.compact
end
# returns the raw JSON details from NHTSA
def details
get_details if @details.nil?
return @details
def invoices
issues.includes(:invoices).flat_map(&:invoices).uniq.compact
end
# Force Upper Case for make numbers
def make=(val)
# The to_s is in case you get nil/non-string
write_attribute(:make, val.to_s.titleize)
super(val.to_s.strip)
end
# Force Upper Case for model numbers
def model=(val)
# The to_s is in case you get nil/non-string
write_attribute(:model, val.to_s.titleize)
super(val.to_s.strip)
end
# Force Upper Case & strip VIN of all illegal chars (for barcode scanner)
def vin=(val)
val = val.to_s.upcase.gsub(/[^A-HJ-NPR-Za-hj-npr-z\d]+/,"")
write_attribute(:vin, val)
# Redmine compatibility shim
def project
nil
end
# search for a vin
def self.search(search)
where("vin LIKE ?", "%#{search}%")
def self.search(query)
return none if query.blank?
q = "%#{sanitize_sql_like(query)}%"
where( "vin LIKE :q OR make LIKE :q OR model LIKE :q OR year LIKE :q", q: q)
end
# decodes a vin and updates self
def decode_vin
get_details
if @details
begin
self.year = @details.year unless @details.year.nil?
self.make = @details.make unless @details.make.nil?
self.model = @details.model unless @details.model.nil?
self.doors = @details.doors unless @details.doors.nil?
self.trim = @details.trim unless @details.trim.nil?
rescue Exception => e
errors.add(:vin, e.message)
# Override the defult redmine seach method to rank results by id
def self.search_result_ranks_and_ids(tokens, user, project = nil, options = {})
return {} if tokens.blank?
scope = self.all
tokens.each do |token|
scope = scope.search(token)
end
ids = scope.distinct.limit(options[:limit] || 100).pluck(:id)
ids.index_with { |id| id }
end
self.name = to_s
def to_s
return vin if year.blank? || make.blank? || model.blank?
suffix = vin.to_s[9..] || vin
"#{year} #{make} #{model} - #{suffix}"
end
private
# init method to pull JSON details from NHTSA
def get_details
if self.vin?
#validate the vin before calling a remote server
validation = NhtsaVin.validate(self.vin)
begin
#if the vin validation failed, raise an exception and exit
raise RuntimeError, validation.error unless validation.valid?
# query NHTSA for details on the vin
query = NhtsaVin.get(self.vin)
raise RuntimeError, query.error unless query.valid?
@details = query.response
rescue Exception => e
errors.add(:vin, e.message)
end
end
def enqueue_vin_decode
VehicleVinDecodeJob.perform_later(id)
end
def normalize_vin
return if vin.blank?
cleaned = vin.to_s.upcase.gsub(/[^A-HJ-NPR-Z\d]/, "")
self.vin = cleaned
end
def log(msg)
Rails.logger.info "[Vehicle] #{msg}"
end
end

View File

@@ -0,0 +1,49 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 - 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.
class VinDecoder
Result = Struct.new(:success?, :data, :error)
def self.call(vin)
new(vin).call
end
def initialize(vin)
@vin = vin
end
def call
log "Decoding VIN"
validation = NhtsaVin.validate(@vin)
return failure(validation.error) unless validation.valid?
query = NhtsaVin.get(@vin)
return failure(query.error) unless query.valid?
success(query.response)
rescue StandardError => e
failure(e.message)
end
private
def success(data)
Result.new(true, data, nil)
end
def failure(error)
log "VIN decode failed for #{@vin}: #{error}"
Result.new(false, nil, error)
end
def log(msg)
Rails.logger.info "[VinDecoder] #{msg}"
end
end

View File

@@ -1,5 +1,5 @@
<h4><%=t(:field_vehicles)%>:</h4>
<%= render partial: 'vehicles/list', locals: { vehicles: customer.vehicles.paginate(page: params[:page]) } %>
<%= render partial: 'vehicles/list', locals: { vehicles: customer.vehicles.paginate(page: params[:page]), show_customer: false, show_checkbox: true } %>
<div style="float: right;">
<%= button_to t(:button_new_vehice), new_customer_vehicle_path(customer), method: :get %>
<%= button_to t(:button_new_vehicle), new_customer_vehicle_path(customer), method: :get %>
</div>

View File

@@ -1,18 +1,17 @@
<div class="vehicle attribute">
<div class="label"><span><%=t(:field_vehicle)%></span>:</div>
<div class="label"><%=t(:field_vehicle)%>:</div>
<div class="value"><%= vehicle %></div>
</div>
<div class="vehicle_vin attribute">
<div class="label"><span><%=t(:field_vin)%></span>:</div>
<div class="value"><%=split_vin[0] if split_vin%><b><%=split_vin[1] if split_vin%></b></div>
<div class="label"><%=t(:field_vin)%>:</div>
<div class="value" id="vin">
<div id="copyLink" onclick="handleCopy(event)"><%=split_vin[0] if split_vin%><b><%=split_vin[1] if split_vin%></b></div>
</div>
</div>
<div class="vehicle_notes attribute">
<div class="label"><span><%=t(:field_notes)%></span>:</div>
<div class="value">
<pre id="note-display" style="text-align: left; white-space: pre-wrap; font-family: inherit; ">
<%=notes%>
</pre>
</div>
<div class="label"><%=t(:field_notes)%>:</div>
<pre class="value" id="note-display" style="text-align: left; white-space: pre-wrap; font-family: inherit; "><%=notes%></pre>
</div>

View File

@@ -8,7 +8,7 @@
<tr>
<th><%= t(:field_customer)%></th>
<td><%= link_to vehicle.customer.name, customer_path(vehicle.customer) %></td>
<td><%= vehicle.customer ? link_to(vehicle.customer.name, customer_path(vehicle.customer)) : t(:no_customer) %></td>
</tr>
<tr>
@@ -18,7 +18,9 @@
<tr>
<th><%= t(:field_vin) %></th>
<td><%= @vin[0] if @vin %><b><%=@vin[1] if @vin%></b></td>
<td>
<div onclick="handleCopy(event)"><%= @vin[0] if @vin %><b><%=@vin[1] if @vin%></b></div>
</td>
</tr>
<th><%= t(:label_trim) %></th>

View File

@@ -6,7 +6,7 @@
<div class="clearfix">
<%=t(:field_customer)%>:
<div class="input">
<%= f.autocomplete_field :customer, autocomplete_customer_name_customers_path, value: @customer.name, update_elements: {id: '#customer_id', value: '#issue_customer'}, required: true %>
<%= f.text_field :customer, class: "customer-name", autocomplete: "off", value: @customer.name, required: true,data: { autocomplete_url: "/customers/autocomplete" } %>
<%= f.hidden_field :customer_id, id: "customer_id", value: @customer.id %>
</div>
</div>

View File

@@ -2,26 +2,37 @@
<% vehicles.each do |vehicle| %>
<div class="row">
<div>
<b><%= link_to "##{vehicle.id}", vehicle_path(vehicle) %> </b>
<div class="container">
<% if show_checkbox %>
<%= check_box_tag "vehicle_ids[]", vehicle.id, false, onchange: "updateLink()", data: { url: vehicle_path(vehicle).html_safe, text: vehicle.to_s }, class: "appointment checkbox" %>
<% else %>
<div class='checkbox'>
</div>
<% end %>
<div class='label-main'>
<%= link_to vehicle.to_s, vehicle_path(vehicle) %>
</div>
<div>
<%= vehicle.to_s %>
<br/>
<div class="label-sub">
<div onclick="handleCopy(event)"><%= vehicle.vin.scan(/.{1,9}/)[0] if vehicle.vin %><b><%=vehicle.vin.scan(/.{1,9}/)[1] if vehicle.vin%></b></div>
<% if show_customer %>
<%= vehicle.customer %>
<br/>
<%= vehicle.vin.scan(/.{1,9}/)[0] if vehicle.vin %><b><%=vehicle.vin.scan(/.{1,9}/)[1] if vehicle.vin%></b>
<% end %>
</div>
</div>
<br/>
</div>
<% end %>
<div class="actions">
<%= will_paginate vehicles %>
</div>
<p><%=t(:label_matching)%> <%=vehicles.count%> <%=t(:field_vehicles) %> </p>
<%=t(:label_matching)%> <%=vehicles.count%> <%=t(:field_vehicles) %>
<% else %>
<p><%=t(:label_no_vehicles)%> <%= params[:search] %>.</p>

View File

@@ -1,4 +1,4 @@
<%= form_tag(vehicles_path, method: "get", id: "search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: t(:label_search_vin), autocomplete: "off" %>
<%= form_tag(vehicles_path, method: "get", id: "vehicles-search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: t(:label_search_vehicles), autocomplete: "off" %>
<%= submit_tag t(:label_search) %>
<% end %>

View File

@@ -1,4 +1,4 @@
<h2><%=t(:label_cusomer_vehicles)%> <span style="float:right"> <%= render partial: 'vehicles/search' %> </span> </h2>
<h2><%=t(:label_customer_vehicles)%> <span style="float:right"> <%= render partial: 'vehicles/search' %> </span> </h2>
<br/>
<%= render partial: 'vehicles/list', locals: {vehicles: @vehicles} %>
<%= render partial: 'vehicles/list', locals: {vehicles: @vehicles, show_customer: true, show_checkbox: false} %>

View File

@@ -1,11 +1,66 @@
<h2><%=t(:field_vehicle)%> #<%=@vehicle.id%></h2>
<% unless @vehicle.vin_decoded? %>
<div id="vin-status" class="flash notice">
<%= t :notice_decoding_vin %>
</div>
<% end %>
<%= render partial: 'vehicles/details', locals: {vehicle: @vehicle} %>
<h3><%=@issues.open.count%> <%=t(:label_open_issues)%></h3>
<div class="splitcontent">
<div class="splitcontentleft">
<h4><%=t(:estimates)%>:</h4>
<%= render partial: 'estimates/list', locals: {estimates: @vehicle.estimates} %>
</div>
<%= render partial: 'issues/list_simple', locals: {issues: @issues.open} %>
<div class="splitcontentleft">
<h4><%=t(:label_invoices)%>:</h4>
<%= render partial: 'invoices/list', locals: {invoices: @vehicle.invoices} %>
</div>
</div>
<h3><%=@open_issues.count%> <%=t(:label_open_issues)%></h3>
<%= render partial: 'issues/list_simple', locals: {issues: @open_issues} %>
<h3><%=@closed_issues.count%> <%=t(:label_closed_issues)%></h3>
<%= render partial: 'issues/list_simple', locals: {issues: (@closed_issues)} %>
<script>
(function() {
const vehicleId = <%= @vehicle.id %>;
const alreadyDecoded = <%= @vehicle.vin_decoded? ? 'true' : 'false' %>;
if (alreadyDecoded) return;
const interval = 3000; // 3 seconds
let attempts = 0;
const maxAttempts = 40; // ~2 minutes
const checkStatus = () => {
fetch(`/vehicles/${vehicleId}/status`, {
headers: { 'Accept': 'application/json' }
})
.then(res => res.json())
.then(data => {
if (data.decoded) {
window.location.reload();
} else {
attempts++;
if (attempts >= maxAttempts) {
clearInterval(timer);
console.warn("VIN decode polling timed out");
}
}
})
.catch(err => {
console.error("Polling error:", err);
clearInterval(timer);
});
};
const timer = setInterval(checkStatus, interval);
})();
</script>

View File

View File

@@ -0,0 +1,45 @@
async function handleCopy(event) {
console.log("Copy link clicked");
let text;
let link;
// Grab the text from our clicked link
if(event.target.tagName.toLowerCase() === 'b'){
text = event.target.parentElement.innerText;
link = event.target.parentElement;
} else {
text = event.target.innerText;
link = event.target;
}
// If the text is already "Copied!", don't do anything
if (text == "Copied!") {
return;
}
try {
// Write to clipboard
await navigator.clipboard.writeText(text);
// Update the UI to show it worked
const originalText = link.innerText;
link.innerHTML = "<b>Copied!</b>";
link.style.color = "#4CAF50"; // Turn green
// Reset after 2 seconds
setTimeout(() => {
// Check if the text is long enough to prevent errors
if (originalText.length >= 8) {
const firstPart = originalText.slice(0, -8);
const lastEight = originalText.slice(-8);
link.innerHTML = `${firstPart}<b>${lastEight}</b>`;
} else {
link.innerText = originalText;
}
link.style.color = "";
}, 2000);
} catch (err) {
console.error('Unable to copy', err);
}
}

View File

@@ -0,0 +1,23 @@
.container {
display: grid;
/* Column 1 for checkbox, Column 2 for text */
grid-template-columns: auto 1fr;
/* Row 1 for 'Vehicle', Row 2 for 'VIN' */
grid-template-rows: auto auto;
align-items: center;
gap: 0 10px; /* Adjust spacing between checkbox and text */
}
.checkbox {
/* This makes the checkbox take up both rows */
grid-row: span 2;
}
.label-main {
font-weight: bold;
}
.label-sub {
font-size: 0.85em;
color: #666;
}

View File

@@ -10,17 +10,28 @@
# English strings go here for Rails i18n
# Usage I18n.t(:label)
en:
field_vehicles: "Vehicles"
alert_no_customer: "Customer no longer exists, check for merged customers or deleted customers in QuickBooks Online."
alert_vehicle_not_created: "Vehicle could not be created."
alert_vehicle_not_deleted: "Vehicle could not be deleted."
alert_vehicle_not_found: "Vehicle not found."
alert_vehicle_not_updated: "Vehicle could not be updated."
button_new_vehicle: "New Vehicle"
field_vehicle: "Vehicle"
field_vehicles: "Vehicles"
field_vin: "VIN"
label_customer_vehicles: "Customer Vehicles"
label_edit: "Edit"
label_year: "Year"
label_edit_customer_vehicle: "Edit Customer Vehicle"
label_make: "Make"
label_model: "Model"
label_no_vehicles: "There are no vehicles containing the term(s)"
label_search_vin: "Search Vehicles by VIN"
label_edit_customer_vehicle: "Edit Customer Vehicle"
label_cusomer_vehicles: "Customer Vehicles"
label_new_vehicle: "New Customer Vehicle"
button_new_vehice: "New Vehicle"
label_no_vehicles: "There are no vehicles containing the term(s)"
label_search_vehicles: "Search Vehicles"
label_year: "Year"
no_customer: "Customer no longer exists"
notice_decoding_vin: "Decoding VIN… this page will update automatically."
notice_vehicle_created: "Vehicle was successfully created."
notice_vehicle_deleted: "Vehicle was successfully deleted."
notice_vehicle_updated: "Vehicle was successfully updated."

View File

@@ -15,4 +15,8 @@ resources :customers do
end
#allow for just vehicles too
resources :vehicles
resources :vehicles do
member do
get :status
end
end

View File

@@ -0,0 +1,17 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 - 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.
class AddTimestamp < ActiveRecord::Migration[7.0]
def change
add_timestamps(:vehicles, null: true)
end
end

View File

@@ -0,0 +1,22 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 - 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.
class AddIndexes < ActiveRecord::Migration[7.0]
def change
add_column :vehicles, :vin_decoded, :boolean, default: false, null: false
add_index :vehicles, :vin_decoded
add_index :vehicles, :vin, unique: true
add_index :vehicles, :make
add_index :vehicles, :model
add_index :vehicles, :year
end
end

20
init.rb
View File

@@ -14,33 +14,31 @@ Redmine::Plugin.register :redmine_qbo_vehicles do
name 'Redmine QBO Vehicles plugin'
author 'Rick Barrette'
description 'This is a plugin for Redmine to intergrate with the redmine_qbo plugin to provide vehicle data tracking'
version '2026.1.4'
version '2026.3.2'
url 'https://github.com/rickbarrette/redmine_qbo_vehicles'
author_url 'https://barrettefabrication.com'
requires_redmine version_or_higher: '6.1.0'
# Ensure redmine_qbo is installed
begin
requires_redmine_plugin :redmine_qbo, version_or_higher: '2026.1.2'
requires_redmine_plugin :redmine_qbo, version_or_higher: '2026.3.13'
rescue Redmine::PluginNotFound
raise 'Please install the redmine_qbo plugin (https://github.com/rickbarrette/redmine_qbo)'
end
# Add safe attributes for core models
Issue.safe_attributes 'vehicle_id'
Issue.safe_attributes :vehicle_id
# Permissions for security
permission :view_vehicles, vehicles: :new, public: false
# Register top menu items
menu :top_menu, :vehicles, { controller: :vehicles, action: :index }, caption: 'Vehicles', if: Proc.new { User.current.logged? }
menu :top_menu, :vehicles, { controller: :vehicles, action: :index }, caption: :field_vehicles, if: Proc.new { User.current.logged? }
Redmine::Search.map do |search|
search.register :vehicles
end
end
# Dynamically load all Hooks & Patches recursively
base_dir = File.join(File.dirname(__FILE__), 'lib')
# '**' looks inside subdirectories, '*.rb' matches Ruby files
Dir.glob(File.join(base_dir, '**', '*.rb')).sort.each do |file|
require file
end
RedmineQboVehicles.setup

View File

@@ -0,0 +1,23 @@
#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 RedmineQboVehicles
def self.setup
Issue.prepend Vehicles::Patches::IssuePatch
Customer.prepend Vehicles::Patches::CustomerPatch
Vehicles::Hooks::CustomerShowHookListener
Vehicles::Hooks::InvoiceHookListener
Vehicles::Hooks::IssuesFormHookListener
Vehicles::Hooks::IssuesShowHookListener
Vehicles::Hooks::PdfHookListener
Vehicles::Hooks::ViewHookListener
end
end

View File

@@ -17,13 +17,13 @@ module Vehicles
# Called by Redmine QBO Invoice
def process_invoice_custom_fields(context={})
Rails.logger.info "redmine_qbo_vehicles.process_invoice_custom_fields"
log "Processing invoice custom fields for invoice ##{context[:invoice].id}"
issue = context[:issue]
# update the invoive custom fields with infomation from the issue if available
context[:invoice].custom_fields.each do |cf|
Rails.logger.info "Checking invoice.custom field: #{cf.name}"
log "Checking invoice custom field: #{cf.name}"
# VIN from the attached vehicle
begin
@@ -32,13 +32,13 @@ module Vehicles
# TODO check cf_sync_confict flag once implemented
if cf.string_value.to_s.blank?
Rails.logger.info "VIN was blank, updating the invoice vin in quickbooks"
log "VIN was blank, updating the invoice vin in quickbooks"
vin = context[:issue].vehicle.vin
break if vin.nil?
if not cf.string_value.to_s.eql? vin
cf.string_value = vin.to_s
Rails.logger.info "VIN has changed"
log "VIN has changed"
context[:is_changed] = true
end
@@ -47,7 +47,7 @@ module Vehicles
end
rescue
#do nothing
Rails.logger.info "redmine_qbo_vehicles.process_invoice_custom_fields failed, skipping"
log "redmine_qbo_vehicles.process_invoice_custom_fields failed, skipping"
return nil
end
end
@@ -56,6 +56,12 @@ module Vehicles
return nil
end
private
def log(msg)
Rails.logger.info "[InvoiceHookListener] #{msg}"
end
end
end

View File

@@ -19,7 +19,7 @@ module Vehicles
context[:controller].send(:render_to_string, {
partial: 'issues/show_issue_view_right',
locals: {
vehicle: link_to(context[:issue].vehicle),
vehicle: context[:issue].vehicle ? link_to(context[:issue].vehicle) : nil,
split_vin: context[:issue].vehicle ? context[:issue].vehicle.vin.to_s.scan(/.{1,9}/) : nil,
notes: context[:issue].vehicle ? context[:issue].vehicle.notes : nil
}

View File

@@ -0,0 +1,24 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 - 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
module Hooks
class ViewHookListener < Redmine::Hook::ViewListener
def view_layouts_base_html_head(context = {})
safe_join([
stylesheet_link_tag('style', plugin: :redmine_qbo_vehicles, media: :all),
javascript_include_tag('copy', plugin: :redmine_qbo_vehicles)
])
end
end
end
end

View File

@@ -14,16 +14,12 @@ module Vehicles
# Patches Redmine QBO Customer dynamically.
# Adds a relationship for vehicle ownership by customers
module CustomerPatch
extend ActiveSupport::Concern
ActiveSupport.on_load(:active_record) do
Customer.class_eval do
prepended do
has_many :vehicles
end
end
end
end
end

View File

@@ -8,23 +8,18 @@
#
#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.
require_dependency 'issue'
module Vehicles
module Patches
# Patches Redmine's Issues dynamically.
# Adds a relationship for attahcing a vehilce to an issue
module IssuePatch
extend ActiveSupport::Concern
ActiveSupport.on_load(:active_record) do
Issue.class_eval do
prepended do
belongs_to :vehicle
end
end
end
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 564 KiB

BIN
screenshots/issue.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 724 KiB

BIN
screenshots/issue_form.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 534 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 540 KiB