Skip to content

Commit

Permalink
Fix income summary totals (#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
zachgoll committed May 17, 2024
1 parent 0d0f766 commit ac46c0c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/transaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Transaction < ApplicationRecord

monetize :amount

scope :inflows, -> { where("amount > 0") }
scope :outflows, -> { where("amount < 0") }
scope :inflows, -> { where("amount <= 0") }
scope :outflows, -> { where("amount > 0") }
scope :active, -> { where(excluded: false) }
scope :with_converted_amount, ->(currency = Current.family.currency) {
# Join with exchange rates to convert the amount to the given currency
Expand Down
10 changes: 10 additions & 0 deletions test/models/transaction_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
require "test_helper"

class TransactionTest < ActiveSupport::TestCase
# See: https://github.com/maybe-finance/maybe/wiki/vision#signage-of-money
test "negative amounts are inflows, positive amounts are outflows to an account" do
inflow_transaction = transactions(:checking_four)
outflow_transaction = transactions(:checking_five)

assert inflow_transaction.amount < 0
assert outflow_transaction.amount >= 0
assert Transaction.inflows.include? inflow_transaction
assert Transaction.outflows.include? outflow_transaction
end
end

0 comments on commit ac46c0c

Please sign in to comment.