Merge branch 'master' into line_items

This commit is contained in:
2018-03-29 22:42:54 -04:00
5 changed files with 13 additions and 31 deletions

View File

@@ -5,7 +5,7 @@ gem 'quickbooks-ruby-base'
gem 'oauth-plugin'
gem 'oauth'
gem 'roxml'
gem 'edmunds_vin'
gem 'nhtsa_vin'
gem 'will_paginate'
gem 'rails-jquery-autocomplete'
gem 'jquery-rails', '~> 3.1.4'

View File

@@ -33,7 +33,7 @@ class CustomersController < ApplicationController
default_search_scope :names
autocomplete :customer, :name, :full => false, :extra_data => [:id]
autocomplete :customer, :name, :full => true, :extra_data => [:id]
def filter_vehicles_by_customer
@filtered_vehicles = Vehicle.all.where(customer_id: params[:selected_customer])

View File

@@ -29,7 +29,8 @@ class Vehicle < ActiveRecord::Base
if year.nil? or make.nil? or model.nil?
return "#{vin}"
else
return "#{year} #{make} #{model}"
split_vin = vin.scan(/.{1,9}/)
return "#{year} #{make} #{model} - #{split_vin[1]}"
end
end
@@ -83,15 +84,15 @@ class Vehicle < ActiveRecord::Base
where("vin LIKE ?", "%#{search}%")
end
private
private
# init method to pull JSON details from Edmunds
def get_details
if self.vin?
begin
query = NhtsaVin.get(self.vin)
raise error if not @details.valid?
@details = query.response = NhtsaVin.get(self.vin)
raise RuntimeError, query.error unless query.valid?
@details = query.response
rescue Exception => e
errors.add(:vin, e.message)
end
@@ -103,9 +104,9 @@ class Vehicle < ActiveRecord::Base
get_details
if @details
begin
self.year = @details.year
self.make = @details.make
self.model = @details.model
self.year = @details.year unless @details.year.nil?
self.make = @details.make unless @details.make.nil?
self.model = @details.model unless @details.model.nil?
rescue Exception => e
errors.add(:vin, e.message)
end
@@ -113,15 +114,4 @@ class Vehicle < ActiveRecord::Base
self.name = to_s
end
# makes a squishvin
# https://api.edmunds.com/api/vehicle/v2/squishvins/#{vin}/?fmt=json&api_key=#{ENV['edmunds_key']}
def vin_squish
if not self.vin? or self.vin.size < 11
# this is to go ahead and query the API, letting them handle the error. :P
return '1000000000A'
end
v = self.vin[0,11]
return v.slice(0,8) + v.slice(9,11)
end
end

View File

@@ -21,16 +21,6 @@
<td><%= vehicle.style %></td>
</tr>
<tr>
<th>Drive</th>
<td><%= vehicle.drive %></td>
</tr>
<tr>
<th>Doors</th>
<td><%= vehicle.doors %></td>
</tr>
<tr>
<th>Notes</th>
<td><%= vehicle.notes %></td>

View File

@@ -41,7 +41,9 @@ module IssuePatch
# Create billable time entries
def bill_time
return if assigned_to.nil?
# Get unbilled time entries
spent_time = time_entries.where(qbo_billed: [false, nil])
spent_hours ||= spent_time.sum(:hours) || 0