Add trim & doors to vehicle

This commit is contained in:
2022-03-06 08:59:48 -05:00
parent 332f07c93d
commit 495243d177
4 changed files with 48 additions and 10 deletions

View File

@@ -58,10 +58,10 @@ class Vehicle < ActiveRecord::Base
end end
# returns the number of doors of the vehicle # returns the number of doors of the vehicle
def doors #def doors
get_details if @details.nil? # get_details if @details.nil?
return @details.doors if @details # return @details.doors if @details
end #end
# Force Upper Case for make numbers # Force Upper Case for make numbers
def make=(val) def make=(val)
@@ -93,8 +93,10 @@ class Vehicle < ActiveRecord::Base
if @details if @details
begin begin
self.year = @details.year unless @details.year.nil? self.year = @details.year unless @details.year.nil?
self.make = @details.make unless @details.make.nil? self.make = @details.make unless @details.make.nil?
self.model = @details.model unless @details.model.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 rescue Exception => e
errors.add(:vin, e.message) errors.add(:vin, e.message)
end end
@@ -110,9 +112,9 @@ private
#validate the vin before calling a remote server #validate the vin before calling a remote server
validation = NhtsaVin.validate(self.vin) validation = NhtsaVin.validate(self.vin)
begin begin
#if the vin validation failed, raise an exception and exit #if the vin validation failed, raise an exception and exit
raise RuntimeError, validation.error unless validation.valid? raise RuntimeError, validation.error unless validation.valid?
# query NHTSA for details on the vin # query NHTSA for details on the vin
query = NhtsaVin.get(self.vin) query = NhtsaVin.get(self.vin)
raise RuntimeError, query.error unless query.valid? raise RuntimeError, query.error unless query.valid?
@details = query.response @details = query.response

View File

@@ -16,6 +16,10 @@
<td><%= @vin[0] if @vin %><b><%=@vin[1] if @vin%></b></td> <td><%= @vin[0] if @vin %><b><%=@vin[1] if @vin%></b></td>
</tr> </tr>
<th><%= t(:label_trim) %></th>
<td><%= vehicle.doors %> <%=t(:label_door)%> <%= vehicle.trim %></td>
</tr>
<tr> <tr>
<th><%= t(:field_notes) %></th> <th><%= t(:field_notes) %></th>
<td><%= vehicle.notes %></td> <td><%= vehicle.notes %></td>

View File

@@ -77,4 +77,6 @@ en:
label_no_estimates: "No Estimates" label_no_estimates: "No Estimates"
label_no_invoices: "No Invoices" label_no_invoices: "No Invoices"
label_invoices: "Invoices" label_invoices: "Invoices"
label_load_customer: "Load Customer" label_load_customer: "Load Customer"
label_door: "Door"
label_trim: "Trim"

View File

@@ -0,0 +1,30 @@
#The MIT License (MIT)
#
#Copyright (c) 2022 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 UpdateVehiclesTrim < ActiveRecord::Migration[5.1]
def change
add_column :vehicles, :doors, :text
add_column :vehicles, :trim, :text
reversible do |direction|
direction.up {
# Update local vehicle database by forcing a save, look at before_save
vehicles = Vehicle.all
vehicles.each { |vehicle|
vehicle.save!
}
}
end
end
end