Class: Deb::Item

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/deb/item.rb

Instance Method Summary collapse

Instance Method Details

#op_signObject



27
28
29
# File 'app/models/deb/item.rb', line 27

def op_sign
  "debit" == kind ? -1 : 1
end

#positive_amountObject



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_balancesObject



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 = .current_balance
  self.balance_after = .current_balance + op_sign * amount
  save!
  .current_balance = balance_after
  .save!
end