transfer: Support transfers of different currencies between accounts. #2243
Reference in New Issue
Block a user
Delete Branch "multi-currency-transfer"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Allow transfer matcher to match transfers to a different currency.
Fixes: #1852.
How do we upvote this lol?
I'll let @zachgoll ultimately weigh in on this, but adding at least a couple of tests for this will go a long way to getting it merged.
@Joelute thanks for the addition here!
Per @Shpigford's comments, we'll need some concise and simple tests that clearly demonstrate that this query works and does not break any of our existing functionality for auto matching and manual matching.
We should also combine this logic into the existing
transfer_match_candidatesquery. There's a ton of logic to reason about with this process, so keeping it centralized in a single query allows use to debug things in one spot if it were to break.bugbot run
Bug: Cross-Currency Transfer Matching Inconsistency
auto_match_transfers! still uses transfer_match_candidates (single-currency scope) even though the commit introduces and switches other call-sites to transfer_match_multi_currency_candidates. As a result, bulk/automatic matching will completely ignore cross-currency transfers while per-transaction matching now considers them, creating inconsistent behaviour and defeating the stated purpose of this change.
app/models/family/auto_transfer_matchable.rb#L59-L808d74954813/app/models/family/auto_transfer_matchable.rb (L59-L80)Fix in Cursor
Was this report helpful? Give feedback by reacting with 👍 or 👎
bugbot run
bugbot run
Bug: Zero Division Error in Transfer Matching
Division by zero error in the transfer matching query. The calculation
ABS(inflow_candidates.amount / (outflow_candidates.amount * exchange_rates.rate))fails ifexchange_rates.rateis 0. While economically invalid, a zero rate is not prevented by theIS NOT NULLcheck and can exist due to data errors, causing the query to crash.app/models/family/auto_transfer_matchable.rb#L42-L43ae80e60bb1/app/models/family/auto_transfer_matchable.rb (L42-L43)Fix in Cursor
Was this report helpful? Give feedback by reacting with 👍 or 👎
Oh, this is something really helpful, I also noticed that It adds the currencies as total without conversion (in the current stable version)
For example:

@ragnarok22 this PR is unrelated, your issue is https://github.com/maybe-finance/maybe/issues/2301.
@zachgoll @Shpigford
Could you guys review this one again please? 🙏
bugbot run
Looking a lot better! left a few suggestions, but otherwise looks good.
@@ -24,12 +22,26 @@ module Family::AutoTransferMatchablerejected_transfers.inflow_transaction_id = inflow_candidates.entryable_id ANDI think we can avoid all of the null / 0 checking with a NULLIF:
@@ -53,4 +98,51 @@ class Family::AutoTransferMatchableTest < ActiveSupport::TestCase@family.auto_match_transfers!I think even when the rate is
0we should go ahead and run the standard matching logic.A value of
0in the exchange rates table would be considered "bad data" and I don't think it is the responsibility of the transfer matcher to handle.So in other words, let's remove this test as I don't think it's testing the right thing.
@@ -24,12 +22,26 @@ module Family::AutoTransferMatchablerejected_transfers.inflow_transaction_id = inflow_candidates.entryable_id ANDLooks cleaner than the current conditions. Updated in the latest commit.
@@ -53,4 +98,51 @@ class Family::AutoTransferMatchableTest < ActiveSupport::TestCase@family.auto_match_transfers!Sounds good, I've removed the testcase in the latest commit.
Hey @zachgoll, I've updated the PR based on the reviews. Please take another look.
Looks good now! Thanks for working through the feedback on this one!
Hi Guys could you please let me know how to update to this? thanks.