mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-11-29 10:24:20 +01:00
6df9724527
This setting was disabled in config/application.rb: `config.active_record.belongs_to_required_by_default = false`, so we must configure the linter accordingly. Also: linting some little bit of code
32 lines
844 B
Ruby
32 lines
844 B
Ruby
# frozen_string_literal: true
|
|
|
|
# user's virtual wallet which can be credited by an admin
|
|
# all subsequent user's transactions will charge the wallet, as the default payment mean, if the wallet amount > 0
|
|
# if the wallet amount is not sufficient, a secondary payment mean will be requested (card or cash, depending on the login context)
|
|
class Wallet < ApplicationRecord
|
|
include AmountConcern
|
|
|
|
belongs_to :invoicing_profile
|
|
has_many :wallet_transactions, dependent: :destroy
|
|
|
|
validates :invoicing_profile, presence: true
|
|
|
|
delegate :user, to: :invoicing_profile
|
|
|
|
def credit(amount)
|
|
if amount.is_a?(Numeric) && amount >= 0
|
|
self.amount += amount
|
|
return save
|
|
end
|
|
false
|
|
end
|
|
|
|
def debit(amount)
|
|
if amount.is_a?(Numeric) && amount >= 0
|
|
self.amount -= amount
|
|
return save
|
|
end
|
|
false
|
|
end
|
|
end
|