1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/app/models/wallet.rb

25 lines
443 B
Ruby
Raw Normal View History

2016-07-18 18:16:54 +02:00
class Wallet < ActiveRecord::Base
2016-07-05 12:30:52 +02:00
include AmountConcern
2016-07-18 18:16:54 +02:00
belongs_to :user
2016-07-05 12:30:52 +02:00
has_many :wallet_transactions, dependent: :destroy
2016-07-04 19:20:10 +02:00
2016-07-18 18:16:54 +02:00
validates :user, presence: true
2016-07-05 11:32:06 +02:00
2016-07-04 19:20:10 +02:00
def credit(amount)
2016-07-05 10:38:39 +02:00
if amount.is_a?(Numeric) and amount >= 0
self.amount += amount
return save
end
false
2016-07-04 19:20:10 +02:00
end
def debit(amount)
2016-07-05 10:38:39 +02:00
if amount.is_a?(Numeric) and amount >= 0
self.amount -= amount
return save
end
false
2016-07-04 19:20:10 +02:00
end
2016-07-18 18:16:54 +02:00
end