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

View File

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

View File

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