Class: Bookkeeper::Account

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/bookkeeper/account.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultObject



31
32
33
34
35
36
# File 'app/models/bookkeeper/account.rb', line 31

def self.default
   = Account.find_by_default(true)
   = Account.create(title: "Default", start_date: Time.now, initial_balance: 0.0, default: true) if .nil?

  
end

Instance Method Details

#rebuild_balanceObject



23
24
25
# File 'app/models/bookkeeper/account.rb', line 23

def rebuild_balance
  self.balance = self.initial_balance + self.incomings.sum(:amount) - self.outgoings.sum(:amount)
end

#update_balanceObject



18
19
20
21
# File 'app/models/bookkeeper/account.rb', line 18

def update_balance
  self.rebuild_balance
  self.save
end

#update_start_dateObject



27
28
29
# File 'app/models/bookkeeper/account.rb', line 27

def update_start_date
  self.update_attribute(:start_date, self.movements.first.created_at)
end