Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

Fix income summary totals (#759)

Zach Gollwitzerac46c0c5a9b4
diff --git a/app/models/transaction.rb b/app/models/transaction.rb
index 68b6b06f..770547ea 100644
--- a/app/models/transaction.rb
+++ b/app/models/transaction.rb
@@ -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
diff --git a/test/models/transaction_test.rb b/test/models/transaction_test.rb
index 9210a737..c5a47fde 100644
--- a/test/models/transaction_test.rb
+++ b/test/models/transaction_test.rb
@@ -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