refactor: jaccounts -> jdeclaredaccounts

This commit is contained in:
Simon Michael 2018-09-17 05:52:13 -07:00
parent 944a49d359
commit 059ad9eb76
8 changed files with 12 additions and 10 deletions

View File

@ -92,7 +92,7 @@ tieAccountParents = tie Nothing
-- | Look up an account's numeric code, if any, from the Journal and set it.
accountSetCodeFrom :: Journal -> Account -> Account
accountSetCodeFrom j a = a{acode=fromMaybe Nothing $ lookup (aname a) (jaccounts j)}
accountSetCodeFrom j a = a{acode=fromMaybe Nothing $ lookup (aname a) (jdeclaredaccounts j)}
-- | Get this account's parent accounts, from the nearest up to the root.
parentAccounts :: Account -> [Account]

View File

@ -163,7 +163,7 @@ instance Sem.Semigroup Journal where
,jparsealiases = jparsealiases j2
-- ,jparsetransactioncount = jparsetransactioncount j1 + jparsetransactioncount j2
,jparsetimeclockentries = jparsetimeclockentries j1 <> jparsetimeclockentries j2
,jaccounts = jaccounts j1 <> jaccounts j2
,jdeclaredaccounts = jdeclaredaccounts j1 <> jdeclaredaccounts j2
,jcommodities = jcommodities j1 <> jcommodities j2
,jinferredcommodities = jinferredcommodities j1 <> jinferredcommodities j2
,jmarketprices = jmarketprices j1 <> jmarketprices j2
@ -190,7 +190,7 @@ nulljournal = Journal {
,jparsealiases = []
-- ,jparsetransactioncount = 0
,jparsetimeclockentries = []
,jaccounts = []
,jdeclaredaccounts = []
,jcommodities = M.fromList []
,jinferredcommodities = M.fromList []
,jmarketprices = []
@ -256,7 +256,7 @@ journalAccountNamesImplied = expandAccountNames . journalAccountNamesUsed
-- | Sorted unique account names declared by account directives in this journal.
journalAccountNamesDeclared :: Journal -> [AccountName]
journalAccountNamesDeclared = nub . sort . map fst . jaccounts
journalAccountNamesDeclared = nub . sort . map fst . jdeclaredaccounts
-- | Sorted unique account names declared by account directives or posted to
-- by transactions in this journal.

View File

@ -360,7 +360,7 @@ data Journal = Journal {
-- ,jparsetransactioncount :: Integer -- ^ the current count of transactions parsed so far (only journal format txns, currently)
,jparsetimeclockentries :: [TimeclockEntry] -- ^ timeclock sessions which have not been clocked out
-- principal data
,jaccounts :: [(AccountName, Maybe AccountCode)] -- ^ accounts that have been declared by account directives
,jdeclaredaccounts :: [(AccountName, Maybe AccountCode)] -- ^ Accounts declared by account directives, in parse order.
,jcommodities :: M.Map CommoditySymbol Commodity -- ^ commodities and formats declared by commodity directives
,jinferredcommodities :: M.Map CommoditySymbol AmountStyle -- ^ commodities and formats inferred from journal amounts XXX misnamed
,jmarketprices :: [MarketPrice]

View File

@ -266,7 +266,7 @@ getAmountStyle commodity = do
return effectiveStyle
pushAccount :: AccountName -> JournalParser m ()
pushAccount acct = modify' (\j -> j{jaccounts = (acct, Nothing) : jaccounts j})
pushAccount acct = modify' (\j -> j{jdeclaredaccounts = (acct, Nothing) : jdeclaredaccounts j})
pushParentAccount :: AccountName -> JournalParser m ()
pushParentAccount acct = modify' (\j -> j{jparseparentaccounts = acct : jparseparentaccounts j})

View File

@ -266,7 +266,7 @@ accountdirectivep = do
newline
skipMany indentedlinep
modify' (\j -> j{jaccounts = (acct, macode) : jaccounts j})
modify' (\j -> j{jdeclaredaccounts = (acct, macode) : jdeclaredaccounts j})
indentedlinep :: JournalParser m String
indentedlinep = lift (skipSome spacenonewline) >> (rstrip <$> lift restofline)

View File

@ -224,7 +224,7 @@ combineBudgetAndActual
-- acodeandname r = (acode', aname)
-- where
-- aname = first6 r
-- macode = fromMaybe Nothing $ lookup aname $ jaccounts j
-- macode = fromMaybe Nothing $ lookup aname $ jdeclaredaccounts j
-- acode' = fromMaybe maxBound macode
--
-- -- Sort the report rows, representing a tree of accounts, by account code and then account name at each level.

View File

@ -217,7 +217,7 @@ multiBalanceReport opts q j =
acodeandname r = (acode', aname)
where
aname = first6 r
macode = fromMaybe Nothing $ lookup aname $ jaccounts j
macode = fromMaybe Nothing $ lookup aname $ jdeclaredaccounts j
acode' = fromMaybe maxBound macode
-- Sort the report rows, representing a tree of accounts, by account code and then account name at each level.

View File

@ -11,6 +11,7 @@ The @accounts@ command lists account names:
-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE CPP #-}
module Hledger.Cli.Commands.Accounts (
@ -49,6 +50,7 @@ accountsmode = (defCommandMode $ ["accounts"] ++ aliases) {
groupUnnamed = [
flagNone ["declared"] (\opts -> setboolopt "declared" opts) "show account names declared with account directives"
,flagNone ["used"] (\opts -> setboolopt "used" opts) "show account names referenced by transactions"
,flagNone ["codes"] (\opts -> setboolopt "codes" opts) "also show numeric account codes"
,flagNone ["tree"] (\opts -> setboolopt "tree" opts) "show short account names, as a tree"
,flagNone ["flat"] (\opts -> setboolopt "flat" opts) "show full account names, as a list (default)"
,flagReq ["drop"] (\s opts -> Right $ setopt "drop" s opts) "N" "flat mode: omit N leading account name parts"
@ -66,7 +68,7 @@ accounts CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do
let q = queryFromOpts d ropts
nodepthq = dbg1 "nodepthq" $ filterQuery (not . queryIsDepth) q
depth = dbg1 "depth" $ queryDepth $ filterQuery queryIsDepth q
matcheddeclaredaccts = dbg1 "matcheddeclaredaccts" $ nub $ sort $ filter (matchesAccount q) $ map fst $ jaccounts j
matcheddeclaredaccts = dbg1 "matcheddeclaredaccts" $ nub $ sort $ filter (matchesAccount q) $ map fst $ jdeclaredaccounts j
matchedps = dbg1 "ps" $ journalPostings $ filterJournalPostings nodepthq j
matchedusedaccts = dbg1 "matchedusedaccts" $ nub $ sort $ filter (not . T.null) $ map (clipAccountName depth) $ map paccount matchedps
used = boolopt "used" rawopts