The personal finance app for everyone (by everyone)
Ruby
Increase FX rate deviation tolerance to 10% when matching transfers (#877)
Jakub Kottnauer011957b4cbfc
diff --git a/app/models/family/auto_transfer_matchable.rb b/app/models/family/auto_transfer_matchable.rbindex 98c70775e6..62e2295fac 100644--- a/app/models/family/auto_transfer_matchable.rb+++ b/app/models/family/auto_transfer_matchable.rb@@ -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::AutoTransferMatchableinflow_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 })diff --git a/test/models/family/auto_transfer_matchable_test.rb b/test/models/family/auto_transfer_matchable_test.rbindex 6fdad008e3..893da1992c 100644--- a/test/models/family/auto_transfer_matchable_test.rb+++ b/test/models/family/auto_transfer_matchable_test.rb@@ -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% boundcreate_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% boundcreate_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 tolerancecreate_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!