Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Export companies and customers to local DB
- CSV.foreach('./risotest.csv', headers: true, header_converters: :symbol, encoding: 'UTF-8') do |row|
- company = Company.find_or_create_by_id(row[:dealerid], {name: row[:name], custom_fields: {dealerid: row[:dealerid]}})
- company.customers.find_or_create_by_id(row[:techid], {
- first_name: row[:first_name],
- last_name: row[:last_name],
- custom_fields: {techid: row[:techid]},
- title: row[:title],
- addresses: [{
- type: 'work',
- # remove the , if any address field is empty
- value: "#{(row[:address].to_s.strip.empty? ? row[:address].to_s : (row[:address] +", ")) +
- (row[:city].to_s.strip.empty? ? row[:city].to_s : (row[:city] + ", ")) +
- (row[:state].to_s.strip.empty? ? row[:state].to_s : (row[:state] + " ")) +
- (row[:zip].to_s.strip.empty? ? row[:zip].to_s : (row[:zip] + ", ")) +
- (row[:country].to_s)}"
- }].select { |x| x[:value].gsub(/,/, '').present? },
- phone_numbers: [{type: 'work', value: row[:phone_numbers]}].select { |x| x[:value].present? }
- emails: [{type: 'work', value: row[:emails]}].select {|x| x.present?}
- })
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement