mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 06:21:23 +00:00
Increase FX rate deviation tolerance to 10% when matching transfers (#877)
* Increase exchange rate deviation tolerance to 10% when matching transfers * Fix test
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
module Family::AutoTransferMatchable
|
||||
def transfer_match_candidates(date_window: 4)
|
||||
def transfer_match_candidates(date_window: 4, exchange_rate_tolerance: 0.1)
|
||||
Entry.select([
|
||||
"inflow_candidates.entryable_id as inflow_transaction_id",
|
||||
"outflow_candidates.entryable_id as outflow_transaction_id",
|
||||
@@ -39,7 +39,7 @@ module Family::AutoTransferMatchable
|
||||
inflow_candidates.amount = -outflow_candidates.amount
|
||||
) OR (
|
||||
inflow_candidates.currency <> outflow_candidates.currency AND
|
||||
ABS(inflow_candidates.amount / NULLIF(outflow_candidates.amount * exchange_rates.rate, 0)) BETWEEN 0.95 AND 1.05
|
||||
ABS(inflow_candidates.amount / NULLIF(outflow_candidates.amount * exchange_rates.rate, 0)) BETWEEN #{1 - exchange_rate_tolerance} AND #{1 + exchange_rate_tolerance}
|
||||
)
|
||||
")
|
||||
.where(existing_transfers: { id: nil })
|
||||
|
||||
@@ -27,7 +27,7 @@ class Family::AutoTransferMatchableTest < ActiveSupport::TestCase
|
||||
@family.auto_match_transfers!
|
||||
end
|
||||
|
||||
# test match within lower 5% bound
|
||||
# test match within lower 10% bound
|
||||
create_transaction(date: 1.day.ago.to_date, account: @depository, amount: 1000)
|
||||
create_transaction(date: Date.current, account: @credit_card, amount: -1330, currency: "CAD")
|
||||
|
||||
@@ -35,7 +35,7 @@ class Family::AutoTransferMatchableTest < ActiveSupport::TestCase
|
||||
@family.auto_match_transfers!
|
||||
end
|
||||
|
||||
# test match within upper 5% bound
|
||||
# test match within upper 10% bound
|
||||
create_transaction(date: 1.day.ago.to_date, account: @depository, amount: 1500)
|
||||
create_transaction(date: Date.current, account: @credit_card, amount: -2189, currency: "CAD")
|
||||
|
||||
@@ -45,7 +45,7 @@ class Family::AutoTransferMatchableTest < ActiveSupport::TestCase
|
||||
|
||||
# test no match outside of slippage tolerance
|
||||
create_transaction(date: 1.day.ago.to_date, account: @depository, amount: 1000)
|
||||
create_transaction(date: Date.current, account: @credit_card, amount: -1320, currency: "CAD")
|
||||
create_transaction(date: Date.current, account: @credit_card, amount: -1250, currency: "CAD")
|
||||
|
||||
assert_difference -> { Transfer.count } => 0 do
|
||||
@family.auto_match_transfers!
|
||||
|
||||
Reference in New Issue
Block a user