refactor: jaccounts -> jdeclaredaccounts
This commit is contained in:
parent
944a49d359
commit
059ad9eb76
@ -92,7 +92,7 @@ tieAccountParents = tie Nothing
|
|||||||
|
|
||||||
-- | Look up an account's numeric code, if any, from the Journal and set it.
|
-- | Look up an account's numeric code, if any, from the Journal and set it.
|
||||||
accountSetCodeFrom :: Journal -> Account -> Account
|
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.
|
-- | Get this account's parent accounts, from the nearest up to the root.
|
||||||
parentAccounts :: Account -> [Account]
|
parentAccounts :: Account -> [Account]
|
||||||
|
|||||||
@ -163,7 +163,7 @@ instance Sem.Semigroup Journal where
|
|||||||
,jparsealiases = jparsealiases j2
|
,jparsealiases = jparsealiases j2
|
||||||
-- ,jparsetransactioncount = jparsetransactioncount j1 + jparsetransactioncount j2
|
-- ,jparsetransactioncount = jparsetransactioncount j1 + jparsetransactioncount j2
|
||||||
,jparsetimeclockentries = jparsetimeclockentries j1 <> jparsetimeclockentries j2
|
,jparsetimeclockentries = jparsetimeclockentries j1 <> jparsetimeclockentries j2
|
||||||
,jaccounts = jaccounts j1 <> jaccounts j2
|
,jdeclaredaccounts = jdeclaredaccounts j1 <> jdeclaredaccounts j2
|
||||||
,jcommodities = jcommodities j1 <> jcommodities j2
|
,jcommodities = jcommodities j1 <> jcommodities j2
|
||||||
,jinferredcommodities = jinferredcommodities j1 <> jinferredcommodities j2
|
,jinferredcommodities = jinferredcommodities j1 <> jinferredcommodities j2
|
||||||
,jmarketprices = jmarketprices j1 <> jmarketprices j2
|
,jmarketprices = jmarketprices j1 <> jmarketprices j2
|
||||||
@ -190,7 +190,7 @@ nulljournal = Journal {
|
|||||||
,jparsealiases = []
|
,jparsealiases = []
|
||||||
-- ,jparsetransactioncount = 0
|
-- ,jparsetransactioncount = 0
|
||||||
,jparsetimeclockentries = []
|
,jparsetimeclockentries = []
|
||||||
,jaccounts = []
|
,jdeclaredaccounts = []
|
||||||
,jcommodities = M.fromList []
|
,jcommodities = M.fromList []
|
||||||
,jinferredcommodities = M.fromList []
|
,jinferredcommodities = M.fromList []
|
||||||
,jmarketprices = []
|
,jmarketprices = []
|
||||||
@ -256,7 +256,7 @@ journalAccountNamesImplied = expandAccountNames . journalAccountNamesUsed
|
|||||||
|
|
||||||
-- | Sorted unique account names declared by account directives in this journal.
|
-- | Sorted unique account names declared by account directives in this journal.
|
||||||
journalAccountNamesDeclared :: Journal -> [AccountName]
|
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
|
-- | Sorted unique account names declared by account directives or posted to
|
||||||
-- by transactions in this journal.
|
-- by transactions in this journal.
|
||||||
|
|||||||
@ -360,7 +360,7 @@ data Journal = Journal {
|
|||||||
-- ,jparsetransactioncount :: Integer -- ^ the current count of transactions parsed so far (only journal format txns, currently)
|
-- ,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
|
,jparsetimeclockentries :: [TimeclockEntry] -- ^ timeclock sessions which have not been clocked out
|
||||||
-- principal data
|
-- 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
|
,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
|
,jinferredcommodities :: M.Map CommoditySymbol AmountStyle -- ^ commodities and formats inferred from journal amounts XXX misnamed
|
||||||
,jmarketprices :: [MarketPrice]
|
,jmarketprices :: [MarketPrice]
|
||||||
|
|||||||
@ -266,7 +266,7 @@ getAmountStyle commodity = do
|
|||||||
return effectiveStyle
|
return effectiveStyle
|
||||||
|
|
||||||
pushAccount :: AccountName -> JournalParser m ()
|
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 :: AccountName -> JournalParser m ()
|
||||||
pushParentAccount acct = modify' (\j -> j{jparseparentaccounts = acct : jparseparentaccounts j})
|
pushParentAccount acct = modify' (\j -> j{jparseparentaccounts = acct : jparseparentaccounts j})
|
||||||
|
|||||||
@ -266,7 +266,7 @@ accountdirectivep = do
|
|||||||
newline
|
newline
|
||||||
skipMany indentedlinep
|
skipMany indentedlinep
|
||||||
|
|
||||||
modify' (\j -> j{jaccounts = (acct, macode) : jaccounts j})
|
modify' (\j -> j{jdeclaredaccounts = (acct, macode) : jdeclaredaccounts j})
|
||||||
|
|
||||||
indentedlinep :: JournalParser m String
|
indentedlinep :: JournalParser m String
|
||||||
indentedlinep = lift (skipSome spacenonewline) >> (rstrip <$> lift restofline)
|
indentedlinep = lift (skipSome spacenonewline) >> (rstrip <$> lift restofline)
|
||||||
|
|||||||
@ -224,7 +224,7 @@ combineBudgetAndActual
|
|||||||
-- acodeandname r = (acode', aname)
|
-- acodeandname r = (acode', aname)
|
||||||
-- where
|
-- where
|
||||||
-- aname = first6 r
|
-- aname = first6 r
|
||||||
-- macode = fromMaybe Nothing $ lookup aname $ jaccounts j
|
-- macode = fromMaybe Nothing $ lookup aname $ jdeclaredaccounts j
|
||||||
-- acode' = fromMaybe maxBound macode
|
-- acode' = fromMaybe maxBound macode
|
||||||
--
|
--
|
||||||
-- -- Sort the report rows, representing a tree of accounts, by account code and then account name at each level.
|
-- -- Sort the report rows, representing a tree of accounts, by account code and then account name at each level.
|
||||||
|
|||||||
@ -217,7 +217,7 @@ multiBalanceReport opts q j =
|
|||||||
acodeandname r = (acode', aname)
|
acodeandname r = (acode', aname)
|
||||||
where
|
where
|
||||||
aname = first6 r
|
aname = first6 r
|
||||||
macode = fromMaybe Nothing $ lookup aname $ jaccounts j
|
macode = fromMaybe Nothing $ lookup aname $ jdeclaredaccounts j
|
||||||
acode' = fromMaybe maxBound macode
|
acode' = fromMaybe maxBound macode
|
||||||
|
|
||||||
-- Sort the report rows, representing a tree of accounts, by account code and then account name at each level.
|
-- Sort the report rows, representing a tree of accounts, by account code and then account name at each level.
|
||||||
|
|||||||
@ -11,6 +11,7 @@ The @accounts@ command lists account names:
|
|||||||
-}
|
-}
|
||||||
|
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
{-# LANGUAGE CPP #-}
|
{-# LANGUAGE CPP #-}
|
||||||
|
|
||||||
module Hledger.Cli.Commands.Accounts (
|
module Hledger.Cli.Commands.Accounts (
|
||||||
@ -49,6 +50,7 @@ accountsmode = (defCommandMode $ ["accounts"] ++ aliases) {
|
|||||||
groupUnnamed = [
|
groupUnnamed = [
|
||||||
flagNone ["declared"] (\opts -> setboolopt "declared" opts) "show account names declared with account directives"
|
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 ["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 ["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)"
|
,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"
|
,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
|
let q = queryFromOpts d ropts
|
||||||
nodepthq = dbg1 "nodepthq" $ filterQuery (not . queryIsDepth) q
|
nodepthq = dbg1 "nodepthq" $ filterQuery (not . queryIsDepth) q
|
||||||
depth = dbg1 "depth" $ queryDepth $ filterQuery 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
|
matchedps = dbg1 "ps" $ journalPostings $ filterJournalPostings nodepthq j
|
||||||
matchedusedaccts = dbg1 "matchedusedaccts" $ nub $ sort $ filter (not . T.null) $ map (clipAccountName depth) $ map paccount matchedps
|
matchedusedaccts = dbg1 "matchedusedaccts" $ nub $ sort $ filter (not . T.null) $ map (clipAccountName depth) $ map paccount matchedps
|
||||||
used = boolopt "used" rawopts
|
used = boolopt "used" rawopts
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user