Added price currency to conference, select currency in basic info and created data rake task for setting old conferences' price currency
This commit is contained in:
parent
9b12830c8f
commit
17488e11c7
8 changed files with 398 additions and 355 deletions
24
lib/tasks/set_conference_currency.rake
Normal file
24
lib/tasks/set_conference_currency.rake
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
namespace :data do
|
||||
desc 'Sets price_currency in all pre-existing Conference records'
|
||||
task set_conference_price_currency: :environment do
|
||||
Conference.all.each do |conference|
|
||||
# if ticket has price_currency it is old and needs to be updated
|
||||
if conference.tickets.first.price_currency
|
||||
# check all tickets have same price currency
|
||||
ticket_pc = conference.tickets.first.price_currency
|
||||
make_change = true
|
||||
conference.tickets.each do |ticket|
|
||||
make_change = false unless ticket.price_currency == ticket_pc
|
||||
end
|
||||
end
|
||||
if make_change
|
||||
conference.update(price_currency: ticket_pc)
|
||||
puts "price currency of #{ticket_pc} set for conference: #{conference.title}."
|
||||
else
|
||||
puts "price currency discrepancy between tickets for conference: #{conference.title}, please check and try again."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue