Add RejectedTransfer model, simplify auto matching #1690
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses and fixes #1630 and #1661 along with a few other simplifications.
Rejected transfers
Previously, the
Transfer
model had 3 possible status codes:approved
,pending
, andrejected
.The
rejected
status introduced a large group of edge cases that made the UI, auto matching logic, and overall transfer domain more confusing:Transfer
records since a user could reject one and then add the same transaction to another. This made it sotransaction.transfer?
needed to query ahas_many
relationship to decide whether a transaction was part of a confirmed transfer.The sole reason we had this status was to keep track of transaction pairs that the user had explicitly rejected to avoid auto-matching them again. Adding
RejectedTransfer
drastically simplifies the required domain logic while giving us a simple way to "remember" which transfers have been rejected by the user already.Auto matching validation updates
Transfer
records with the same transaction in both, leaving the user with a confusing matching approve/reject scenarioConsolidation of auto-matching logic
Previously, there were 2 places in the codebase we were duplicating the "auto matching" conditions:
Transfer.auto_match_for_account
entry.transfer_match_candidates
This created a brittle scenario where a user was able to manually match transactions based on a different criteria than we were matching during account syncs. This logic is now consolidated into a scope of
account.transfer_match_candidates
which is consumed by bothaccount.auto_match_transfers!
andentry.transfer_match_candidates
.