mirror of
https://github.com/fspc/BikeShed-1.git
synced 2026-09-16 16:31:38 -04:00
BikeCsvImporter: add status logs
This commit is contained in:
@@ -22,5 +22,10 @@ class BikeCsvImporter
|
||||
@bike_model_cache[model] = BikeModel.where('lower(model) = ?', model.downcase).first
|
||||
end
|
||||
end
|
||||
|
||||
def cached_log_bike_action(action)
|
||||
@log_bike_action_id_cache ||= {}
|
||||
@log_bike_action_id_cache[action] ||= ActsAsLoggable::BikeAction.find_by_action(action)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
class BikeCsvImporter
|
||||
module Logs
|
||||
def log_entry_gone(bike, bike_hash)
|
||||
if clean_value(bike_hash['gone']).to_s =~ /y/i
|
||||
log_entry bike, log_entry_date(clean_value(bike_hash['date out'])), 'COMPLETED', 'Gone'
|
||||
end
|
||||
end
|
||||
|
||||
def log_entry_acquired(bike, bike_hash)
|
||||
if clean_value(bike_hash['date in'])
|
||||
log_entry bike, log_entry_date(clean_value(bike_hash['date in'])), 'ACQUIRED'
|
||||
end
|
||||
end
|
||||
|
||||
def log_entry_comment(bike, bike_hash)
|
||||
if clean_value(bike_hash['comment']).present?
|
||||
log_entry bike, nil, 'NOTE', clean_value(bike_hash['comment'])
|
||||
end
|
||||
end
|
||||
|
||||
def log_entry_date(value)
|
||||
return unless value
|
||||
Date.strptime value, '%m/%d/%y' rescue nil
|
||||
end
|
||||
|
||||
def log_entry(bike, date, type, description = nil)
|
||||
date ||= DateTime.now
|
||||
bike_action = cached_log_bike_action(type)
|
||||
|
||||
ActsAsLoggable::Log.new(
|
||||
loggable_type: bike.class.to_s,
|
||||
loggable_id: bike.id || bike.shop_id.to_i, # for dry run
|
||||
log_action_type: bike_action.class.to_s,
|
||||
log_action_id: bike_action.id,
|
||||
start_date: date,
|
||||
end_date: date,
|
||||
description: description,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user