Class: Bookkeeping::Entry

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/bookkeeping/entry.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepare(options = {}, &block) ⇒ Object



28
29
30
# File 'app/models/bookkeeping/entry.rb', line 28

def self.prepare(options = {}, &block)
  Bookkeeping::DSL.new(new(options), &block).build
end

Instance Method Details

#rollback(ref = nil) ⇒ Object

TODO: not work



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/models/bookkeeping/entry.rb', line 33

def rollback(ref = nil)
  tran = self
  inverse_entry = self.class.prepare do
    tran.debit_amounts.each { |di| debit(di., -di.amount) }
    tran.credit_amounts.each { |ci| credit(ci., -ci.amount) }
    transactionable(ref || tran)
    description("Rollback of #{tran.description}")
  end
  inverse_entry.save!

  unless inverse_entry.new_record?
    self.rollback_entry = inverse_entry
    self.save!
  end

  inverse_entry
end