mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2025-11-08 17:04:23 -05:00
Merge branch 'master' of github.com:rickbarrette/redmine_qbo
This commit is contained in:
@@ -20,7 +20,7 @@ class Vehicle < ActiveRecord::Base
|
|||||||
validates_presence_of :customer
|
validates_presence_of :customer
|
||||||
validates :vin, uniqueness: true
|
validates :vin, uniqueness: true
|
||||||
before_save :decode_vin
|
before_save :decode_vin
|
||||||
after_initialize :get_details
|
after_find :get_details
|
||||||
|
|
||||||
self.primary_key = :id
|
self.primary_key = :id
|
||||||
|
|
||||||
@@ -84,21 +84,6 @@ class Vehicle < ActiveRecord::Base
|
|||||||
where("vin LIKE ?", "%#{search}%")
|
where("vin LIKE ?", "%#{search}%")
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
# init method to pull JSON details from Edmunds
|
|
||||||
def get_details
|
|
||||||
if self.vin?
|
|
||||||
begin
|
|
||||||
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
|
|
||||||
end
|
|
||||||
|
|
||||||
# decodes a vin and updates self
|
# decodes a vin and updates self
|
||||||
def decode_vin
|
def decode_vin
|
||||||
get_details
|
get_details
|
||||||
@@ -114,4 +99,19 @@ private
|
|||||||
self.name = to_s
|
self.name = to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
# init method to pull JSON details from Edmunds
|
||||||
|
def get_details
|
||||||
|
if self.vin?
|
||||||
|
begin
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user