Class: ActsAsAccount::Journal
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ActsAsAccount::Journal
- Defined in:
- lib/acts_as_account/journal.rb
Class Method Summary collapse
Instance Method Summary collapse
- #transfer(amount, from_account, to_account, reference = nil, valuta = Time.now) ⇒ Object
- #transfers ⇒ Object
Class Method Details
.clear_current ⇒ Object
17 18 19 |
# File 'lib/acts_as_account/journal.rb', line 17 def clear_current Thread.current[:acts_as_account_current] = nil end |
.current ⇒ Object
13 14 15 |
# File 'lib/acts_as_account/journal.rb', line 13 def current Thread.current[:acts_as_account_current] ||= create! end |
Instance Method Details
#transfer(amount, from_account, to_account, reference = nil, valuta = Time.now) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/acts_as_account/journal.rb', line 28 def transfer(amount, from_account, to_account, reference = nil, valuta = Time.now) transaction do if (amount < 0) # change order if amount is negative amount, from_account, to_account = -amount, to_account, from_account end logger.debug { "ActsAsAccount::Journal.transfer amount: #{amount} from:#{from_account.id} to:#{to_account.id} reference:#{reference.class.name}(#{reference.id}) valuta:#{valuta}" } if logger # to avoid possible deadlocks we need to ensure that the locking order is always # the same therfore the sort by id. [from_account, to_account].sort_by(&:id).map(&:lock!) add_posting(-amount, from_account, to_account, reference, valuta) add_posting( amount, to_account, from_account, reference, valuta) end end |