Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jl - nexus pricing import #1013

Merged
merged 6 commits into from
Aug 2, 2017
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 16 additions & 10 deletions lib/tasks/import_pricing_maps.rake
Expand Up @@ -55,6 +55,9 @@ namespace :data do
file
end

imported_maps = CSV.open("tmp/imported_maps.csv", "w")
imported_maps << ['Service ID', 'Map Created', 'Import Error']

puts "Press CTRL-C to exit"
puts ""

Expand All @@ -66,15 +69,16 @@ namespace :data do
puts "#"*50
puts "Starting import"
input_file = Rails.root.join("db", "imports", file)
CSV.foreach(input_file, :headers => true) do |row|
service = Service.find(row['service_id'].to_i)
CSV.foreach(input_file, :headers => true, skip_blanks: true, skip_lines: /^(?:,\s*)+$/) do |row|

service = Service.find(row['Service ID'].to_i)

pricing_map = service.pricing_maps.build(
:full_rate => Service.dollars_to_cents(row['full_rate'].to_s.strip.gsub("$", "").gsub(",", "")),
:corporate_rate => (row['corporate_rate'].blank? ? nil : Service.dollars_to_cents(row['corporate_rate'].to_s.strip.gsub("$", "").gsub(",", ""))),
:federal_rate => (row['federal_rate'].blank? ? nil : Service.dollars_to_cents(row['federal_rate'].to_s.strip.gsub("$", "").gsub(",", ""))),
:member_rate => (row['member_rate'].blank? ? nil : Service.dollars_to_cents(row['member_rate'].to_s.strip.gsub("$", "").gsub(",", ""))),
:other_rate => (row['other_rate'].blank? ? nil : Service.dollars_to_cents(row['other_rate'].to_s.strip.gsub("$", "").gsub(",", ""))),
:corporate_rate => (row['corporate_rate'].nil? || row['corporate_rate'].blank? ? nil : Service.dollars_to_cents(row['corporate_rate'].to_s.strip.gsub("$", "").gsub(",", ""))),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't blank? check for "" and nil. See https://apidock.com/rails/Object/blank%3f

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't see this. Changing it back now.

:federal_rate => (row['federal_rate'].nil? || row['federal_rate'].blank? ? nil : Service.dollars_to_cents(row['federal_rate'].to_s.strip.gsub("$", "").gsub(",", ""))),
:member_rate => (row['member_rate'].nil? || row['member_rate'].blank? ? nil : Service.dollars_to_cents(row['member_rate'].to_s.strip.gsub("$", "").gsub(",", ""))),
:other_rate => (row['other_rate'].nil? || row['other_rate'].blank? ? nil : Service.dollars_to_cents(row['other_rate'].to_s.strip.gsub("$", "").gsub(",", ""))),
:unit_type => row['unit_type'],
:quantity_type => row['quantity_type'],
:unit_factor => row['unit_factor'],
Expand All @@ -88,17 +92,19 @@ namespace :data do
if pricing_map.valid?
puts "New pricing map created for #{service.name}"
puts " full_rate = $ #{pricing_map.full_rate / 100}"
puts " corporate_rate = $ #{pricing_map.corporate_rate / 100}"
puts " federal_rate = $ #{pricing_map.federal_rate / 100}"
puts " member_rate = $ #{pricing_map.member_rate / 100}"
puts " other_rate = $ #{pricing_map.other_rate / 100}"
puts " corporate_rate = $ #{pricing_map.corporate_rate? ? (pricing_map.corporate_rate / 100) : 0}"
puts " federal_rate = $ #{pricing_map.federal_rate? ? (pricing_map.federal_rate / 100) : 0}"
puts " member_rate = $ #{pricing_map.member_rate? ? (pricing_map.member_rate / 100) : 0}"
puts " other_rate = $ #{pricing_map.other_rate? ? (pricing_map.other_rate / 100) : 0}"
puts ""
imported_maps << [service.id, "New pricing map created for #{service.name}", '']
pricing_map.save
else
puts "#"*50
puts "Error importing pricing map"
puts service.inspect
puts pricing_map.inspect
imported_maps << [service.id, '', pricing_map.errors]
puts service.errors
puts pricing_map.errors
end
Expand Down