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
|
|
@ -8,14 +8,10 @@ class Ticket < ApplicationRecord
|
|||
has_paper_trail meta: { conference_id: :conference_id },
|
||||
ignore: %i[updated_at]
|
||||
|
||||
monetize :price_cents, with_model_currency: :price_currency
|
||||
monetize :price_cents, with_currency: ->(ticket) { ticket.conference.price_currency }
|
||||
|
||||
scope :for_registration, -> { where(registration_ticket: true) }
|
||||
|
||||
# This validation is for the sake of simplicity.
|
||||
# If we would allow different currencies per conference we also have to handle convertions between currencies!
|
||||
validate :tickets_of_conference_have_same_currency
|
||||
|
||||
validates :price_cents, :price_currency, :title, presence: true
|
||||
|
||||
validates :price_cents, numericality: { greater_than_or_equal_to: 0 }
|
||||
|
|
@ -79,6 +75,10 @@ class Ticket < ApplicationRecord
|
|||
|
||||
private
|
||||
|
||||
def get_price_currency
|
||||
'GBP'
|
||||
end
|
||||
|
||||
def tickets_of_conference_have_same_currency
|
||||
tickets = Ticket.where(conference_id: conference_id)
|
||||
return if tickets.count.zero? || (tickets.count == 1 && self == tickets.first)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
input_html: { required: 'required' }
|
||||
= f.input :short_title, hint: "A short and unique handle for your conference, using only letters, numbers, underscores, and dashes. This will be used to identify your conference in URLs etc. Example: 'froscon2011'",
|
||||
input_html: { required: 'required', pattern: '[a-zA-Z0-9_-]+', title: 'Only letters, numbers, underscores, and dashes.' }, prepend: conferences_url + '/'
|
||||
= f.input :price_currency, as: :select, class: 'form-control', collection: ['USD', 'EUR', 'GBP', 'INR', 'CNY', 'CHF'], include_blank: false, hint: "Please select the currency in which the tickets for this conference will be sold"
|
||||
= f.inputs 'Scheduling' do
|
||||
= f.input :timezone, as: :time_zone, default: Time.zone.name, hint: 'Please select in what time zone your conference will take place.'
|
||||
= f.input :start_date, as: :string, input_html: { id: 'conference-start-datepicker', required: 'required' }
|
||||
|
|
|
|||
|
|
@ -12,7 +12,10 @@
|
|||
= f.input :title, input_html: { autofocus: true }
|
||||
= f.input :description, input_html: { rows: 5, data: { provide: 'markdown-editable' } }
|
||||
= f.input :price
|
||||
= f.input :price_currency, as: :select, class: 'form-control', collection: ['USD', 'EUR', 'GBP', 'INR', 'CNY', 'CHF'], include_blank: false
|
||||
%label
|
||||
Currency
|
||||
%p
|
||||
= @conference.price_currency
|
||||
= f.input :registration_ticket, hint: 'A registration ticket is with which user register for the conference.'
|
||||
%p.text-right
|
||||
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue