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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue