tab/app/models/request.rb

33 lines
694 B
Ruby
Raw Normal View History

2017-01-09 15:46:43 +01:00
class Request < ActiveRecord::Base
2017-01-09 16:40:58 +01:00
include BaseTransaction
2017-01-09 15:46:43 +01:00
enum status: [:open, :confirmed, :declined]
def confirm!
return unless open?
2017-01-09 16:40:58 +01:00
Transaction.create info
Notification.create user: creditor,message: confirmed_message
2017-01-09 16:22:58 +01:00
2017-01-09 15:46:43 +01:00
update_attributes status: :confirmed
end
def decline!
return unless open?
2017-01-09 16:40:58 +01:00
Notification.create user: creditor, message: declined_message
2017-01-09 15:46:43 +01:00
update_attributes status: :declined
end
private
2017-01-09 16:40:58 +01:00
def confirmed_message
"Your request for €#{amount/100.0} for \"#{message}\" has been accepted by #{debtor.name}."
end
def declined_message
"#{debtor.name} refuses to pay €#{amount/100.0} for \"#{message}\"."
2017-01-09 15:46:43 +01:00
end
end