match full account name when (any) account pattern contains :, as ledger seems to
This commit is contained in:
parent
760befef89
commit
7a69efec70
@ -138,7 +138,7 @@ showBalanceReport opts args l = acctsstr ++ totalstr
|
|||||||
-- select accounts for which we should show balances, based on the options
|
-- select accounts for which we should show balances, based on the options
|
||||||
balancereportaccts :: Bool -> [String] -> Ledger -> [Account]
|
balancereportaccts :: Bool -> [String] -> Ledger -> [Account]
|
||||||
balancereportaccts False [] l = topAccounts l
|
balancereportaccts False [] l = topAccounts l
|
||||||
balancereportaccts False pats l = accountsMatching (regexFor pats) l
|
balancereportaccts False pats l = accountsMatching pats l
|
||||||
balancereportaccts True pats l = addsubaccts l $ balancereportaccts False pats l
|
balancereportaccts True pats l = addsubaccts l $ balancereportaccts False pats l
|
||||||
|
|
||||||
-- add (in tree order) any missing subacccounts to a list of accounts
|
-- add (in tree order) any missing subacccounts to a list of accounts
|
||||||
|
|||||||
@ -68,9 +68,14 @@ accounts l = drop 1 $ flatten $ ledgerAccountTree 9999 l
|
|||||||
topAccounts :: Ledger -> [Account]
|
topAccounts :: Ledger -> [Account]
|
||||||
topAccounts l = map root $ branches $ ledgerAccountTree 9999 l
|
topAccounts l = map root $ branches $ ledgerAccountTree 9999 l
|
||||||
|
|
||||||
-- | Accounts in ledger whose leafname matches the pattern, in tree order
|
-- | Accounts in ledger whose name matches the pattern, in tree order.
|
||||||
accountsMatching :: Regex -> Ledger -> [Account]
|
-- Like ledger (I think), if the pattern contains : we match the full
|
||||||
accountsMatching pat l = filter (containsRegex pat . accountLeafName . aname) $ accounts l
|
-- name, otherwise just the leaf name.
|
||||||
|
accountsMatching :: [String] -> Ledger -> [Account]
|
||||||
|
accountsMatching pats l = filter (containsRegex (regexFor pats) . name) $ accounts l
|
||||||
|
where name = if any (elem ':') pats
|
||||||
|
then aname
|
||||||
|
else accountLeafName . aname
|
||||||
|
|
||||||
-- | List a ledger account's immediate subaccounts
|
-- | List a ledger account's immediate subaccounts
|
||||||
subAccounts :: Ledger -> Account -> [Account]
|
subAccounts :: Ledger -> Account -> [Account]
|
||||||
|
|||||||
10
Tests.hs
10
Tests.hs
@ -181,6 +181,16 @@ balancecommandtests =
|
|||||||
\ $-1\n\
|
\ $-1\n\
|
||||||
\" --"
|
\" --"
|
||||||
(showBalanceReport [] ["cash","saving"] l)
|
(showBalanceReport [] ["cash","saving"] l)
|
||||||
|
,
|
||||||
|
"balance report with multi-part account name" ~:
|
||||||
|
do
|
||||||
|
l <- ledgerfromfile "sample.ledger"
|
||||||
|
assertequal
|
||||||
|
" $1 expenses:food\n\
|
||||||
|
\--------------------\n\
|
||||||
|
\ $1\n\
|
||||||
|
\" --"
|
||||||
|
$ showBalanceReport [] ["expenses:food"] l
|
||||||
]
|
]
|
||||||
|
|
||||||
-- | Assert a parsed thing equals some expected thing, or print a parse error.
|
-- | Assert a parsed thing equals some expected thing, or print a parse error.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user