Merge remote-tracking branch 'origin/dev'

This commit is contained in:
2017-11-13 21:37:28 -05:00
3 changed files with 16 additions and 10 deletions

View File

@@ -12,8 +12,6 @@ class Vehicle < ActiveRecord::Base
unloadable
API_KEY = Setting.plugin_redmine_qbo['settingsEdmundsAPIKey']
belongs_to :customer
has_many :issues, :foreign_key => 'vehicles_id'
@@ -21,8 +19,6 @@ class Vehicle < ActiveRecord::Base
validates_presence_of :customer
validates :vin, uniqueness: true
#validates :year, numericality: { only_integer: true }
before_save :decode_vin
after_initialize :get_details
@@ -30,7 +26,11 @@ class Vehicle < ActiveRecord::Base
# returns a human readable string
def to_s
return "#{year} #{make} #{model}"
if year.nil? or make.nil? or model.nil?
return "#{vin}"
else
return "#{year} #{make} #{model}"
end
end
# returns the raw JSON details from EMUNDS
@@ -71,8 +71,9 @@ class Vehicle < ActiveRecord::Base
# Force Upper Case for VIN numbers
def vin=(val)
# The to_s is in case you get nil/non-string
write_attribute(:vin, val.to_s.scan(/^[A-Za-z0-9]+$/).join.upcase)
#strip VIN of all illegal chars (for barcode scanner)
val = val.to_s.upcase.gsub(/[^A-HJ-NPR-Za-hj-npr-z\d]+/,"")
write_attribute(:vin, val)
end
# search for a vin
@@ -97,8 +98,7 @@ class Vehicle < ActiveRecord::Base
# returns the Edmunds decoder service
def get_decoder
#TODO API Code via Settings
return decoder = Edmunds::Vin.new(API_KEY)
return decoder = Edmunds::Vin.new(Setting.plugin_redmine_qbo['settingsEdmundsAPIKey'])
end
# decodes a vin and updates self

View File

@@ -4,6 +4,8 @@
<%= text_field_tag :search, params[:search], placeholder: "Search Customers" %>
<%= submit_tag "Search" %>
<% end %>
<%= button_to "New Customer", new_customer_path, method: :get%>
<%= button_to "Sync", qbo_sync_path, method: :get%>
<br/>
<% if @customers.present? %>
<br/>

View File

@@ -33,7 +33,11 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
customer_id = f.hidden_field :customer_id, :id => "issue_customer_id"
if context[:issue].customer
vehicles = customer.vehicles.pluck(:name, :id).sort!
if customer.vehicles
vehicles = customer.vehicles.pluck(:name, :id)
else
vehicles = [nil].compact
end
estimates = customer.qbo_estimates.pluck(:doc_number, :id).sort! {|x, y| y <=> x}
else
vehicles = [nil].compact