2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-06-12 20:03:43 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
|
|
|
|
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
|
2019-02-01 19:40:24 +00:00
|
|
|
class Donation < ApplicationRecord
|
2019-08-06 14:06:02 +00:00
|
|
|
# :date, # datetime (when this donation was made)
|
|
|
|
# :amount, # int (in cents)
|
|
|
|
# :recurring, # bool
|
|
|
|
# :anonymous, # bool
|
|
|
|
# :email, # str (cached email of the donor)
|
|
|
|
# :designation, # text
|
|
|
|
# :dedication, # text
|
|
|
|
# :comment, # text
|
|
|
|
# :origin_url, # text
|
|
|
|
# :nonprofit_id, :nonprofit,
|
|
|
|
# :card_id, :card, # Card with which any charges were made
|
|
|
|
# :supporter_id, :supporter,
|
|
|
|
# :profile_id, :profile,
|
|
|
|
# :campaign_id, :campaign,
|
|
|
|
# :payment_id, :payment,
|
|
|
|
# :event_id, :event,
|
|
|
|
# :direct_debit_detail_id, :direct_debit_detail,
|
2019-07-30 21:29:24 +00:00
|
|
|
# :payment_provider
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
validates :amount, presence: true, numericality: { only_integer: true }
|
|
|
|
validates :supporter, presence: true
|
|
|
|
validates :nonprofit, presence: true
|
|
|
|
validates_associated :charges
|
|
|
|
validates :payment_provider, inclusion: { in: %w[credit_card sepa] }, allow_blank: true
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
has_many :charges
|
|
|
|
has_many :campaign_gifts, dependent: :destroy
|
|
|
|
has_many :campaign_gift_options, through: :campaign_gifts
|
|
|
|
has_many :activities, as: :attachment, dependent: :destroy
|
|
|
|
has_many :payments
|
|
|
|
has_one :recurring_donation
|
|
|
|
has_one :payment
|
|
|
|
has_one :offsite_payment
|
|
|
|
has_one :tracking
|
|
|
|
belongs_to :supporter
|
|
|
|
belongs_to :card
|
|
|
|
belongs_to :direct_debit_detail
|
|
|
|
belongs_to :profile
|
|
|
|
belongs_to :nonprofit
|
|
|
|
belongs_to :campaign
|
|
|
|
belongs_to :event
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2021-02-08 20:55:31 +00:00
|
|
|
has_one :modern_donation, inverse_of: :legacy_donation
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
scope :anonymous, -> { where(anonymous: true) }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|