zbrock/billcrush

Sum of transaction amounts is wrong

Closed this issue · 2 comments

Seems to have something to do with the includes on @Transactions. AR is constructing a new relation under the hood that pulls in multiple instances of certain transactions and sums the amounts, which results in some double counting. Dropping them fixes the issue for me:

diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index 9e87aa0..69324a6 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -22,7 +22,7 @@ class GroupsController < ApplicationController
       cookies[:show_help] = nil
     end
     @members = @group.members
-    @transactions = @group.transactions.where({:active => true}).includes([:debits => :member, :credits => :member])
+    @transactions = @group.transactions.where({:active => true})
     @new_transaction = @group.transactions.build
     # get rid of the new ones
     @members.reload

Fixed in 1806d1d