2019-06-03 16:00:09 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# track of all transactions payed using the given wallet
|
2020-03-25 10:16:47 +01:00
|
|
|
class WalletTransaction < ApplicationRecord
|
2016-07-05 12:30:52 +02:00
|
|
|
include AmountConcern
|
|
|
|
|
2019-06-03 16:00:09 +02:00
|
|
|
belongs_to :invoicing_profile
|
2016-07-04 19:20:10 +02:00
|
|
|
belongs_to :wallet
|
|
|
|
belongs_to :reservation
|
2021-05-25 17:28:35 +02:00
|
|
|
# what was paid with the wallet
|
2022-10-11 10:59:48 +02:00
|
|
|
has_one :invoice, dependent: :nullify
|
|
|
|
has_one :payment_schedule, dependent: :nullify
|
2021-05-25 17:28:35 +02:00
|
|
|
# how the wallet was credited
|
|
|
|
has_one :invoice_item, as: :object, dependent: :destroy
|
2016-07-05 12:15:26 +02:00
|
|
|
|
2022-10-11 10:59:48 +02:00
|
|
|
validates :transaction_type, inclusion: { in: %w[credit debit] }
|
2022-10-11 11:43:32 +02:00
|
|
|
validates :invoicing_profile, :wallet, presence: true
|
2019-06-03 16:00:09 +02:00
|
|
|
|
2022-10-11 10:59:48 +02:00
|
|
|
delegate :user, to: :invoicing_profile
|
2021-05-28 17:34:20 +02:00
|
|
|
|
|
|
|
def original_invoice
|
|
|
|
invoice_item.invoice
|
|
|
|
end
|
2016-07-04 19:20:10 +02:00
|
|
|
end
|