Show which legs a transfer cannot pair, and what would pair them

The transfers screen counted unpaired legs per definition but never said
which transactions they were; finding them meant retyping the definition
into the builder. A ⚠ row now opens onto its legs, newest first, each
naming the missing side and what that side would have had to be:

  revolut → ?  arriving leg  +250.00 in other matching *FROM REVOLUT*,
                             dated 2026-02-01 to 2026-02-11

That description comes from transfers.Engine.Want, next to
bestCounterpart, so it is stated in the terms the pairing actually uses:
the other half of the definition, the window, and the amount -- exact,
widened only by the definition's own tolerance, and "any amount" across
currencies, where amounts are not compared. When the other account has
nothing imported at all, the line says so, since that is the usual cause.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-02 19:43:13 +02:00
co-authored by Claude Opus 5.5
parent 17428a4f51
commit 7f5b4846ef
7 changed files with 240 additions and 14 deletions
+37
View File
@@ -353,3 +353,40 @@ func TestEqualGapPrefersTheNearerAmount(t *testing.T) {
t.Errorf("paired with %d, want 3: same gap, exact amount", res.Pairs[0].In.ID)
}
}
// Want describes the missing side in the terms the pairing judges it by: the
// other definition half, the window, and the amount — exact by default,
// widened only by the definition's own tolerance, unchecked across currencies.
func TestWantDescribesTheMissingSide(t *testing.T) {
eur := func(string) string { return "EUR" }
out := Leg{Def: 0, Out: true, Txn: txn(1, "nlb", "2026-03-06", "TRANSFER TO REVOLUT", -50000)}
got := engine(topUp).Want(out, eur)
want := Wanted{Account: "revolut", Desc: "*FROM NLB*", From: "2026-03-01", To: "2026-03-11", Amount: 50000}
if got != want {
t.Errorf("arriving side = %+v, want %+v", got, want)
}
in := Leg{Def: 0, Txn: txn(2, "revolut", "2026-03-09", "Top-up from NLB", 50000)}
got = engine(topUp).Want(in, eur)
want = Wanted{Account: "nlb", Desc: "*TO REVOLUT*", From: "2026-03-04", To: "2026-03-14", Amount: -50000}
if got != want {
t.Errorf("leaving side = %+v, want %+v", got, want)
}
fee := topUp
fee.TolerancePct = 1.5
if got := engine(fee).Want(out, eur); got.TolerancePct != 1.5 || got.AnyAmount {
t.Errorf("tolerant = %+v, want the definition's 1.5%%", got)
}
usd := func(slug string) string {
if slug == "revolut" {
return "USD"
}
return "EUR"
}
if got := engine(fee).Want(out, usd); !got.AnyAmount || got.TolerancePct != 0 {
t.Errorf("cross-currency = %+v, want any amount and no tolerance", got)
}
}