Skip to content

Commit

Permalink
Added description to the gem
Browse files Browse the repository at this point in the history
  • Loading branch information
meriton committed Nov 16, 2015
1 parent 6967dd5 commit d1472ca
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added lib/.DS_Store
Binary file not shown.
13 changes: 7 additions & 6 deletions lib/acts_as_account/journal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,34 @@ def transfers
end
end

def transfer(amount, from_account, to_account, reference = nil, valuta = Time.now)
def transfer(amount, from_account, to_account, reference = nil, valuta = Time.now, description = nil)
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
logger.debug { "ActsAsAccount::Journal.transfer amount: #{amount} from:#{from_account.id} to:#{to_account.id} reference:#{reference.class.name}(#{reference.id}) valuta:#{valuta} description:#{description}" } 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)
add_posting(-amount, from_account, to_account, reference, valuta, description)
add_posting( amount, to_account, from_account, reference, valuta, description)
end
end

private

def add_posting(amount, account, other_account, reference, valuta)
def add_posting(amount, account, other_account, reference, valuta, description)
posting = postings.build(
:amount => amount,
:account => account,
:other_account => other_account,
:reference => reference,
:valuta => valuta)
:valuta => valuta,
:description => description)

account.class.update_counters account.id, :postings_count => 1, :balance => posting.amount

Expand Down

0 comments on commit d1472ca

Please sign in to comment.