Class: Bookkeeper::Account
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Bookkeeper::Account
- Defined in:
- app/models/bookkeeper/account.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.default ⇒ Object
31 32 33 34 35 36 |
# File 'app/models/bookkeeper/account.rb', line 31 def self.default account = Account.find_by_default(true) account = Account.create(title: "Default", start_date: Time.now, initial_balance: 0.0, default: true) if account.nil? account end |
Instance Method Details
#rebuild_balance ⇒ Object
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_balance ⇒ Object
18 19 20 21 |
# File 'app/models/bookkeeper/account.rb', line 18 def update_balance self.rebuild_balance self.save end |
#update_start_date ⇒ Object
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 |