Files
2015-04-29 10:21:12 +02:00

17 lines
442 B
Ruby

class ListPayment
include SimplyStored::Couch
include ActiveModel::SerializerSupport
property :amount
property :source # bitcoin, apple_pay, etc...
belongs_to :list
belongs_to :user
after_save :close_list_when_is_paid
validates :list_id, presence: true
def close_list_when_is_paid
amount_paid = list.list_payments.inject(0.0){|sum, payment| sum + payment.amount}
list.close! if amount_paid >= list.price
end
end