close: --close-desc/--open-desc customise the descriptions (#1165)

This commit is contained in:
Simon Michael 2020-01-22 14:15:30 -08:00
parent 4bb840a0f3
commit f1110d163d
3 changed files with 138 additions and 121 deletions

View File

@ -29,6 +29,8 @@ closemode = hledgerCommandMode
,flagNone ["opening"] (setboolopt "opening") "show just opening transaction"
,flagReq ["close-to"] (\s opts -> Right $ setopt "close-to" s opts) "ACCT" ("account to transfer closing balances to (default: "++defclosingacct++")")
,flagReq ["open-from"] (\s opts -> Right $ setopt "open-from" s opts) "ACCT" ("account to transfer opening balances from (default: "++defopeningacct++")")
,flagReq ["close-desc"] (\s opts -> Right $ setopt "close-desc" s opts) "DESC" ("description for closing transaction (default: "++defclosingdesc++")")
,flagReq ["open-desc"] (\s opts -> Right $ setopt "open-desc" s opts) "DESC" ("description for opening transaction (default: "++defopeningdesc++")")
,flagNone ["explicit","x"] (setboolopt "explicit") "show all amounts explicitly"
,flagNone ["interleaved"] (setboolopt "interleaved") "keep equity and non-equity postings adjacent"
,flagNone ["show-costs"] (setboolopt "show-costs") "keep balances with different costs separate"
@ -49,15 +51,27 @@ close CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do
(o, c) -> (o, c)
-- accounts to close to and open from
-- if a name is specified for only one, it is used for both
-- if only one is specified, it is used for both
(closingacct, openingacct) =
let (mc, mo) = (T.pack <$> maybestringopt "close-to" rawopts, T.pack <$> maybestringopt "open-from" rawopts)
let (mc, mo) =
(T.pack <$> maybestringopt "close-to" rawopts, T.pack <$> maybestringopt "open-from" rawopts)
in case (mc, mo) of
(Just c, Just o) -> (c, o)
(Just c, Nothing) -> (c, c)
(Nothing, Just o) -> (o, o)
(Nothing, Nothing) -> (T.pack defclosingacct, T.pack defopeningacct)
-- descriptions to use for the closing/opening transactions
-- if only one is specified, it is used for both
(closingdesc, openingdesc) =
let (mc, mo) =
(T.pack <$> maybestringopt "close-desc" rawopts, T.pack <$> maybestringopt "open-desc" rawopts)
in case (mc, mo) of
(Just c, Just o) -> (c, o)
(Just c, Nothing) -> (c, c)
(Nothing, Just o) -> (o, o)
(Nothing, Nothing) -> (T.pack defclosingdesc, T.pack defopeningdesc)
-- dates of the closing and opening transactions
ropts_ = ropts{balancetype_=HistoricalBalance, accountlistmode_=ALFlat}
q = queryFromOpts today ropts_
@ -84,7 +98,7 @@ close CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do
interleaved = boolopt "interleaved" rawopts
-- the closing transaction
closingtxn = nulltransaction{tdate=closingdate, tdescription=defclosingdesc, tpostings=closingps}
closingtxn = nulltransaction{tdate=closingdate, tdescription=closingdesc, tpostings=closingps}
closingps =
concat [
[posting{paccount = a
@ -114,7 +128,7 @@ close CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do
++ [posting{paccount=closingacct, pamount=if explicit then mapMixedAmount precise totalamt else missingmixedamt} | not interleaved]
-- the opening transaction
openingtxn = nulltransaction{tdate=openingdate, tdescription=defopeningdesc, tpostings=openingps}
openingtxn = nulltransaction{tdate=openingdate, tdescription=openingdesc, tpostings=openingps}
openingps =
concat [
[posting{paccount = a

View File

@ -10,16 +10,19 @@ _FLAGS
You can choose to print just one of these transactions by using the
`--opening` or `--closing` flag.
One posting to `equity:opening/closing balances`,
with an implicit amount, is added to balance these transactions,
by default.
You can choose different closing/opening account names with the
`--close-to` and `--open-from` options.
If you specify only one, it is used for both.
One posting to `equity:opening/closing balances`, with an implicit
amount, is added to balance the transactions, by default.
You can customise this account name with the `--close-to` and
`--open-from` options. (If you specify only one, it is used in both
transactions.)
Similarly, you can customise the transaction descriptions with
`--close-desc` and `--open-desc`.
With `--x/--explicit`, the equity posting's amount will be shown.
If it involves multiple commodities, a posting for each commodity
will be shown (like the print command).
will be shown (as with the print command).
With `--interleaved`, the equity postings are shown next to the
postings they balance, which makes troubleshooting easier.

View File

@ -23,13 +23,13 @@ $ hledger close -f- -p 2016 assets liabilities
assets:bank $-80 = $0
assets:cash $-10 = $0
liabilities $-25 = $0
equity:closing balances
equity:opening/closing balances
2017-01-01 opening balances
assets:bank $80 = $80
assets:cash $10 = $10
liabilities $25 = $25
equity:opening balances
equity:opening/closing balances
>=0
@ -41,11 +41,11 @@ $ hledger close -f- -p 2016 assets liabilities
$ hledger close -f- -b2017/6/1 -e2018
2017-12-31 closing balances
a -1 = 0
equity:closing balances
equity:opening/closing balances
2018-01-01 opening balances
a 1 = 1
equity:opening balances
equity:opening/closing balances
>=0
@ -73,7 +73,7 @@ $ hledger close -f- -p 2016 assets liabilities --opening
assets:bank $80 = $80
assets:cash $10 = $10
liabilities $25 = $25
equity:opening balances
equity:opening/closing balances
>=0
@ -101,7 +101,7 @@ $ hledger close -f- -p 2016 assets liabilities --closing
assets:bank $-80 = $0
assets:cash $-10 = $0
liabilities $-25 = $0
equity:closing balances
equity:opening/closing balances
>=0
@ -130,13 +130,13 @@ $ hledger close -f- -p 2016 assets liabilities --opening --closing -x
assets:bank $-80 = $0
assets:cash $-10 = $0
liabilities $-25 = $0
equity:closing balances $115
equity:opening/closing balances $115
2017-01-01 opening balances
assets:bank $80 = $80
assets:cash $10 = $10
liabilities $25 = $25
equity:opening balances $-115
equity:opening/closing balances $-115
>=0
@ -150,11 +150,11 @@ $ hledger close -f- -p 2016 assets liabilities --opening --closing -x
$ hledger -f- close assets -p 2019 -x
2019-12-31 closing balances
assets -2A = 0A
equity:closing balances 2A
equity:opening/closing balances 2A
2020-01-01 opening balances
assets 2A = 2A
equity:opening balances -2A
equity:opening/closing balances -2A
>=0
@ -165,14 +165,14 @@ $ hledger -f- close assets -p 2019 --show-costs -x
2019-12-31 closing balances
assets -1A @ 1B
assets -1A @ 1C = 0A
equity:closing balances 1A @ 1B
equity:closing balances 1A @ 1C
equity:opening/closing balances 1A @ 1B
equity:opening/closing balances 1A @ 1C
2020-01-01 opening balances
assets 1A @ 1B
assets 1A @ 1C = 2A
equity:opening balances -1A @ 1B
equity:opening balances -1A @ 1C
equity:opening/closing balances -1A @ 1B
equity:opening/closing balances -1A @ 1C
>=0
@ -188,11 +188,11 @@ $ hledger -f- close assets -p 2019 --show-costs -x
$ hledger -f- close assets -p 2019 -x
2019-12-31 closing balances
assets -2A = 0A
equity:closing balances 2A
equity:opening/closing balances 2A
2020-01-01 opening balances
assets 2A = 2A
equity:opening balances -2A
equity:opening/closing balances -2A
>=0
@ -208,14 +208,14 @@ $ hledger -f- close assets -p 2019 --show-costs -x
2019-12-31 closing balances
assets -1A @ 1B
assets -1A @ 2B = 0A
equity:closing balances 1A @ 1B
equity:closing balances 1A @ 2B
equity:opening/closing balances 1A @ 1B
equity:opening/closing balances 1A @ 2B
2020-01-01 opening balances
assets 1A @ 1B
assets 1A @ 2B = 2A
equity:opening balances -1A @ 1B
equity:opening balances -1A @ 2B
equity:opening/closing balances -1A @ 1B
equity:opening/closing balances -1A @ 2B
>=0
@ -250,10 +250,10 @@ $ hledger -f- close -p 2016 assets liabilities --show-costs -x
liabilities:employer $5,000.00 @ 0.93 EUR
liabilities:employer $5,000.00 @ 0.95 EUR = $0.00
liabilities:employer -1.00 EUR = 0.00 EUR
equity:closing balances $10,000.00
equity:closing balances $-5,000.00 @ 0.93 EUR
equity:closing balances $-5,000.00 @ 0.95 EUR
equity:closing balances 5,734.00 EUR
equity:opening/closing balances $10,000.00
equity:opening/closing balances $-5,000.00 @ 0.93 EUR
equity:opening/closing balances $-5,000.00 @ 0.95 EUR
equity:opening/closing balances 5,734.00 EUR
2017-01-01 opening balances
assets:bank 5,733.00 EUR = 5,733.00 EUR
@ -261,10 +261,10 @@ $ hledger -f- close -p 2016 assets liabilities --show-costs -x
liabilities:employer $-5,000.00 @ 0.93 EUR
liabilities:employer $-5,000.00 @ 0.95 EUR = $0.00
liabilities:employer 1.00 EUR = 1.00 EUR
equity:opening balances $-10,000.00
equity:opening balances $5,000.00 @ 0.93 EUR
equity:opening balances $5,000.00 @ 0.95 EUR
equity:opening balances -5,734.00 EUR
equity:opening/closing balances $-10,000.00
equity:opening/closing balances $5,000.00 @ 0.93 EUR
equity:opening/closing balances $5,000.00 @ 0.95 EUR
equity:opening/closing balances -5,734.00 EUR
>=0
@ -274,27 +274,27 @@ $ hledger -f- close -p 2016 assets liabilities --show-costs -x
$ hledger -f- close -p 2016 assets liabilities --interleaved --show-costs -x
2016-12-31 closing balances
assets:bank -5,733.00 EUR = 0.00 EUR
equity:closing balances 5,733.00 EUR
equity:opening/closing balances 5,733.00 EUR
liabilities:employer $-10,000.00
equity:closing balances $10,000.00
equity:opening/closing balances $10,000.00
liabilities:employer $5,000.00 @ 0.93 EUR
equity:closing balances $-5,000.00 @ 0.93 EUR
equity:opening/closing balances $-5,000.00 @ 0.93 EUR
liabilities:employer $5,000.00 @ 0.95 EUR = $0.00
equity:closing balances $-5,000.00 @ 0.95 EUR
equity:opening/closing balances $-5,000.00 @ 0.95 EUR
liabilities:employer -1.00 EUR = 0.00 EUR
equity:closing balances 1.00 EUR
equity:opening/closing balances 1.00 EUR
2017-01-01 opening balances
assets:bank 5,733.00 EUR = 5,733.00 EUR
equity:opening balances -5,733.00 EUR
equity:opening/closing balances -5,733.00 EUR
liabilities:employer $10,000.00
equity:opening balances $-10,000.00
equity:opening/closing balances $-10,000.00
liabilities:employer $-5,000.00 @ 0.93 EUR
equity:opening balances $5,000.00 @ 0.93 EUR
equity:opening/closing balances $5,000.00 @ 0.93 EUR
liabilities:employer $-5,000.00 @ 0.95 EUR = $0.00
equity:opening balances $5,000.00 @ 0.95 EUR
equity:opening/closing balances $5,000.00 @ 0.95 EUR
liabilities:employer 1.00 EUR = 1.00 EUR
equity:opening balances -1.00 EUR
equity:opening/closing balances -1.00 EUR
>=0
@ -317,17 +317,17 @@ $ hledger -f- close -p 2019 assets --show-costs -x
assets:aaa AAA -510.00000000 = AAA 0.00000000
assets:usd $-49.50
assets:usd $49.390001 @ AAA 10.3528242505 = $0.00
equity:closing balances $49.50
equity:closing balances $-49.390001 @ AAA 10.3528242505
equity:closing balances AAA 510.00000000
equity:opening/closing balances $49.50
equity:opening/closing balances $-49.390001 @ AAA 10.3528242505
equity:opening/closing balances AAA 510.00000000
2020-01-01 opening balances
assets:aaa AAA 510.00000000 = AAA 510.00000000
assets:usd $49.50
assets:usd $-49.390001 @ AAA 10.3528242505 = $0.109999
equity:opening balances $-49.50
equity:opening balances $49.390001 @ AAA 10.3528242505
equity:opening balances AAA -510.00000000
equity:opening/closing balances $-49.50
equity:opening/closing balances $49.390001 @ AAA 10.3528242505
equity:opening/closing balances AAA -510.00000000
>=0
@ -335,14 +335,14 @@ $ hledger -f- close -p 2019 assets --show-costs -x
$ hledger -f- close -p 2019 assets --interleaved -x
2019-12-31 closing balances
assets:aaa AAA -510.00000000 = AAA 0.00000000
equity:closing balances AAA 510.00000000
equity:opening/closing balances AAA 510.00000000
assets:usd $-0.109999 = $0.00
equity:closing balances $0.109999
equity:opening/closing balances $0.109999
2020-01-01 opening balances
assets:aaa AAA 510.00000000 = AAA 510.00000000
equity:opening balances AAA -510.00000000
equity:opening/closing balances AAA -510.00000000
assets:usd $0.109999 = $0.109999
equity:opening balances $-0.109999
equity:opening/closing balances $-0.109999
>=0