From 8310eaa6ff11c0401684f3fc1a9bba1058e36f6c Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 4 Feb 2010 15:57:19 +0000 Subject: [PATCH] resolve conflicts/explain (Add: filter relevant transactions by account) Previously, we supported "hledger add [DESCRIPTION]". A DESCRIPTION just pre-filled the description field and bypassed that prompt, after which existing transactions with similar descriptions were offered as defaults/reminders. Now, we support "hledger add [ACCOUNTPATTERN]" instead. After the description prompt, existing transactions with similar descriptions *and* which match ACCOUNTPATTERN are offered as defaults. This can be helpful eg with a multi-person ledger, to match only your own transactions. --- Commands/Add.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Commands/Add.hs b/Commands/Add.hs index bb8a85b00..a6922121a 100644 --- a/Commands/Add.hs +++ b/Commands/Add.hs @@ -178,13 +178,13 @@ compareLedgerDescriptions s t = compareStrings s' t' t' = simplify t simplify = filter (not . (`elem` "0123456789")) -transactionsSimilarTo :: Ledger -> String -> [(Double,LedgerTransaction)] -transactionsSimilarTo l s = +transactionsSimilarTo :: Ledger -> [String] -> String -> [(Double,Transaction)] +transactionsSimilarTo l apats s = sortBy compareRelevanceAndRecency $ filter ((> threshold).fst) [(compareLedgerDescriptions s $ tdescription t, t) | t <- ts] where - compareRelevanceAndRecency (n1,t1) (n2,t2) = compare (n2,ltdate t2) (n1,ltdate t1) - ts = ledger_txns $ rawledger l + compareRelevanceAndRecency (n1,t1) (n2,t2) = compare (n2,tdate t2) (n1,tdate t1) + ts = jtxns $ filterJournalTransactionsByAccount apats $ journal l threshold = 0