Class: Deb::Item
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Deb::Item
- Defined in:
- app/models/deb/item.rb
Instance Method Summary collapse
- #op_sign ⇒ Object
-
#positive_amount ⇒ Object
attr_accessible :account, :amount.
- #update_balances ⇒ Object
Instance Method Details
#op_sign ⇒ Object
27 28 29 |
# File 'app/models/deb/item.rb', line 27 def op_sign "debit" == kind ? -1 : 1 end |
#positive_amount ⇒ Object
attr_accessible :account, :amount
13 14 15 |
# File 'app/models/deb/item.rb', line 13 def positive_amount errors.add(:amount, "should be positive") unless amount > 0 end |
#update_balances ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'app/models/deb/item.rb', line 17 def update_balances return if @balances_updated @balances_updated = true self.balance_before = account.current_balance self.balance_after = account.current_balance + op_sign * amount save! account.current_balance = balance_after account.save! end |