Transfer Matching: Larger match date window for manual matching (#514)

This commit is contained in:
Dylan Corrales
2025-12-30 13:06:40 -05:00
committed by GitHub
parent 7915fee62c
commit 4e87eead2c
3 changed files with 9 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
module Family::AutoTransferMatchable
def transfer_match_candidates
def transfer_match_candidates(date_window: 4)
Entry.select([
"inflow_candidates.entryable_id as inflow_transaction_id",
"outflow_candidates.entryable_id as outflow_transaction_id",
@@ -10,7 +10,7 @@ module Family::AutoTransferMatchable
inflow_candidates.amount < 0 AND
outflow_candidates.amount > 0 AND
inflow_candidates.account_id <> outflow_candidates.account_id AND
inflow_candidates.date BETWEEN outflow_candidates.date - 4 AND outflow_candidates.date + 4
inflow_candidates.date BETWEEN outflow_candidates.date - #{date_window.to_i} AND outflow_candidates.date + #{date_window.to_i}
)
").joins("
LEFT JOIN transfers existing_transfers ON (

View File

@@ -14,11 +14,11 @@ module Transaction::Transferable
transfer_as_inflow || transfer_as_outflow
end
def transfer_match_candidates
def transfer_match_candidates(date_window: 30)
candidates_scope = if self.entry.amount.negative?
family_matches_scope.where("inflow_candidates.entryable_id = ?", self.id)
family_matches_scope(date_window: date_window).where("inflow_candidates.entryable_id = ?", self.id)
else
family_matches_scope.where("outflow_candidates.entryable_id = ?", self.id)
family_matches_scope(date_window: date_window).where("outflow_candidates.entryable_id = ?", self.id)
end
candidates_scope.map do |match|
@@ -30,7 +30,7 @@ module Transaction::Transferable
end
private
def family_matches_scope
self.entry.account.family.transfer_match_candidates
def family_matches_scope(date_window:)
self.entry.account.family.transfer_match_candidates(date_window: date_window)
end
end

View File

@@ -133,6 +133,7 @@ class Transfer < ApplicationRecord
return unless inflow_transaction&.entry && outflow_transaction&.entry
date_diff = (inflow_transaction.entry.date - outflow_transaction.entry.date).abs
errors.add(:base, "Must be within 4 days") if date_diff > 4
max_days = status == "confirmed" ? 30 : 4
errors.add(:base, "Must be within #{max_days} days") if date_diff > max_days
end
end