Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Store SnapTrade REIMBURSEMENT and PROMOTION as cash inflows (#5891)

lucasudar13235e16d9e5
diff --git a/app/models/snaptrade_account/activities_processor.rb b/app/models/snaptrade_account/activities_processor.rb
index 32238ff1fe..710cada171 100644
--- a/app/models/snaptrade_account/activities_processor.rb
+++ b/app/models/snaptrade_account/activities_processor.rb
@@ -44,6 +44,12 @@ class SnaptradeAccount::ActivitiesProcessor
"INTERNAL_ASSET_TRANSFER_IN" => { category: :trade, label: "Transfer", sign: :buy, zero_amount: :unconditional },
"INTERNAL_ASSET_TRANSFER_OUT" => { category: :trade, label: "Transfer", sign: :sell, zero_amount: :unconditional },
+ # Account credits: cashback paid into an account, fee refunds, sign-up bonuses
+ # (Wealthsimple). SnapTrade signs them from the account side, positive when
+ # money comes in; without a rule that amount was stored as an expense.
+ "REIMBURSEMENT" => { category: :cash, label: "Other", cash_flow: :invert },
+ "PROMOTION" => { category: :cash, label: "Other", cash_flow: :invert },
+
# Unit-dependent types:
# When units are present and non-zero, treated as a trade preserving signed units.
# When units are nil/zero, treated as a cash activity.
diff --git a/test/models/snaptrade_account/activities_processor_test.rb b/test/models/snaptrade_account/activities_processor_test.rb
index 90d9c973da..a4d226921f 100644
--- a/test/models/snaptrade_account/activities_processor_test.rb
+++ b/test/models/snaptrade_account/activities_processor_test.rb
@@ -365,6 +365,32 @@ class SnaptradeAccount::ActivitiesProcessorTest < ActiveSupport::TestCase
assert_equal "Other", entry.entryable.investment_activity_label
end
+ test "processes REIMBURSEMENT and PROMOTION as negative cash inflows" do
+ process_activities(
+ build_cash_activity(id: "reimb_001", type: "REIMBURSEMENT", amount: 216.23, settlement_date: Date.current.to_s),
+ build_cash_activity(id: "promo_001", type: "PROMOTION", amount: 5.00, settlement_date: Date.current.to_s)
+ )
+
+ reimbursement = snaptrade_entry("reimb_001")
+ promotion = snaptrade_entry("promo_001")
+
+ assert_not_nil reimbursement
+ assert_not_nil promotion
+ assert_equal(-216.23, reimbursement.amount.to_f, "cashback paid into the account must be stored as an inflow")
+ assert_equal(-5.00, promotion.amount.to_f, "a promotional bonus must be stored as an inflow")
+ assert_equal "Other", reimbursement.entryable.investment_activity_label
+ end
+
+ test "processes a negative REIMBURSEMENT (clawback) as an outflow" do
+ process_activities(
+ build_cash_activity(id: "reimb_neg_001", type: "REIMBURSEMENT", amount: -12.50, settlement_date: Date.current.to_s)
+ )
+
+ entry = snaptrade_entry("reimb_neg_001")
+ assert_not_nil entry
+ assert_equal 12.50, entry.amount.to_f
+ end
+
test "processes RETURN_OF_CAPITAL, DISTRIBUTION, and SUBSTITUTE_DIVIDEND as negative cash inflows with Dividend label" do
process_activities(
build_cash_activity(id: "roc_001", type: "RETURN_OF_CAPITAL", amount: 75.00, settlement_date: Date.current.to_s, symbol: "VTI"),