close: hide equity amounts by default, for simpler entries (#1165)

-x/--explicit shows them, as with print.
This commit is contained in:
Simon Michael 2020-01-22 12:50:19 -08:00
parent 2645b76ff0
commit 7500002ee5
3 changed files with 40 additions and 29 deletions

View File

@ -27,6 +27,7 @@ closemode = hledgerCommandMode
,flagNone ["opening"] (setboolopt "opening") "show just opening transaction" ,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 ["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 ["open-from"] (\s opts -> Right $ setopt "open-from" s opts) "ACCT" ("account to transfer opening balances from (default: "++defopeningacct++")")
,flagNone ["explicit","x"] (setboolopt "explicit") "show all amounts explicitly"
,flagNone ["interleaved"] (setboolopt "interleaved") "keep equity and non-equity postings adjacent" ,flagNone ["interleaved"] (setboolopt "interleaved") "keep equity and non-equity postings adjacent"
,flagNone ["show-costs"] (setboolopt "show-costs") "keep balances with different costs separate" ,flagNone ["show-costs"] (setboolopt "show-costs") "keep balances with different costs separate"
] ]
@ -61,6 +62,9 @@ close CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do
openingdate = fromMaybe today $ queryEndDate False q openingdate = fromMaybe today $ queryEndDate False q
closingdate = addDays (-1) openingdate closingdate = addDays (-1) openingdate
-- should we show the amount(s) on the equity posting(s) ?
explicit = boolopt "explicit" rawopts
-- should we preserve cost information ? -- should we preserve cost information ?
normalise = case boolopt "show-costs" rawopts of normalise = case boolopt "show-costs" rawopts of
True -> normaliseMixedAmount True -> normaliseMixedAmount
@ -105,7 +109,7 @@ close CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do
-- or a final multicommodity posting transferring all balances to equity -- or a final multicommodity posting transferring all balances to equity
-- (print will show this as multiple single-commodity postings) -- (print will show this as multiple single-commodity postings)
++ [posting{paccount=closingacct, pamount=mapMixedAmount precise totalamt} | not interleaved] ++ [posting{paccount=closingacct, pamount=if explicit then mapMixedAmount precise totalamt else missingmixedamt} | not interleaved]
-- the opening transaction -- the opening transaction
openingtxn = nulltransaction{tdate=openingdate, tdescription="opening balances", tpostings=openingps} openingtxn = nulltransaction{tdate=openingdate, tdescription="opening balances", tpostings=openingps}
@ -129,7 +133,7 @@ close CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do
, let commoditysum = (sum bs)] , let commoditysum = (sum bs)]
, (b, mcommoditysum) <- bs' , (b, mcommoditysum) <- bs'
] ]
++ [posting{paccount=openingacct, pamount=mapMixedAmount precise $ negate totalamt} | not interleaved] ++ [posting{paccount=openingacct, pamount=if explicit then mapMixedAmount precise (negate totalamt) else missingmixedamt} | not interleaved]
-- print them -- print them
when closing $ putStr $ showTransaction closingtxn when closing $ putStr $ showTransaction closingtxn

View File

@ -16,18 +16,24 @@ by default. You can choose different account names with the
`--close-to` and `--open-from` options. If you specify only one of `--close-to` and `--open-from` options. If you specify only one of
these, it is used for both. these, it is used for both.
The "equity" postings are shown at the end of the transaction By default, a single balancing equity posting is added at the end of
by default (and are combined when possible). these journal entries, with the amount left implicit.
With `--interleaved`, they are shown next to each posting they
balance, which is better for troubleshooting (and may generate more postings).
When the balances being closed have cost information (because With `--x/--explicit`, the balancing amount is shown, and if
transaction prices were recorded), `--show-costs` will preserve it. multiple commodities are involved, multiple single-commodity equity
Balances with different costs are closed/reopened separately, postings are shown (like the print command).
and balance -B reports will be unchanged after the transition.
Note this can generate many postings, With `--interleaved`, the equity postings are shown next to each
if you have a lot of foreign currency or investment transactions. posting they balance, which can be better for troubleshooting (and can
By default, transaction prices are ignored. generate more postings).
By default, transaction prices in the journal are ignored when
generating the closing/opening transactions.
With `--show-costs`, this cost information is preserved,
so that `balance -B` reports will be unchanged after the transition.
Separate postings are generated for each cost in each commodity.
Note this can generate very large journal entries, if you have many
foreign currency or investment transactions.
### close usage ### close usage

View File

@ -23,13 +23,13 @@ $ hledger close -f- -p 2016 assets liabilities
assets:bank $-80 = $0 assets:bank $-80 = $0
assets:cash $-10 = $0 assets:cash $-10 = $0
liabilities $-25 = $0 liabilities $-25 = $0
equity:closing balances $115 equity:closing balances
2017-01-01 opening balances 2017-01-01 opening balances
assets:bank $80 = $80 assets:bank $80 = $80
assets:cash $10 = $10 assets:cash $10 = $10
liabilities $25 = $25 liabilities $25 = $25
equity:opening balances $-115 equity:opening balances
>=0 >=0
@ -41,11 +41,11 @@ $ hledger close -f- -p 2016 assets liabilities
$ hledger close -f- -b2017/6/1 -e2018 $ hledger close -f- -b2017/6/1 -e2018
2017-12-31 closing balances 2017-12-31 closing balances
a -1 = 0 a -1 = 0
equity:closing balances 1 equity:closing balances
2018-01-01 opening balances 2018-01-01 opening balances
a 1 = 1 a 1 = 1
equity:opening balances -1 equity:opening balances
>=0 >=0
@ -73,11 +73,11 @@ $ hledger close -f- -p 2016 assets liabilities --opening
assets:bank $80 = $80 assets:bank $80 = $80
assets:cash $10 = $10 assets:cash $10 = $10
liabilities $25 = $25 liabilities $25 = $25
equity:opening balances $-115 equity:opening balances
>=0 >=0
# 4. Print just the closing transaction # 4. Print just the closing transaction.
< <
2016/1/1 open 2016/1/1 open
assets:bank $100 assets:bank $100
@ -101,11 +101,12 @@ $ hledger close -f- -p 2016 assets liabilities --closing
assets:bank $-80 = $0 assets:bank $-80 = $0
assets:cash $-10 = $0 assets:cash $-10 = $0
liabilities $-25 = $0 liabilities $-25 = $0
equity:closing balances $115 equity:closing balances
>=0 >=0
# 5. Supplying --opening --closing is the same as just "close" # 5. Supplying --opening --closing is the same as just "close"
# Also -x makes it show the equity amounts.
< <
2016/1/1 open 2016/1/1 open
assets:bank $100 assets:bank $100
@ -124,7 +125,7 @@ $ hledger close -f- -p 2016 assets liabilities --closing
liabilities $25 liabilities $25
assets:cash assets:cash
$ hledger close -f- -p 2016 assets liabilities --opening --closing $ hledger close -f- -p 2016 assets liabilities --opening --closing -x
2016-12-31 closing balances 2016-12-31 closing balances
assets:bank $-80 = $0 assets:bank $-80 = $0
assets:cash $-10 = $0 assets:cash $-10 = $0
@ -146,7 +147,7 @@ $ hledger close -f- -p 2016 assets liabilities --opening --closing
assets 1A @ 1C assets 1A @ 1C
equity equity
$ hledger -f- close assets -p 2019 $ hledger -f- close assets -p 2019 -x
2019-12-31 closing balances 2019-12-31 closing balances
assets -2A = 0A assets -2A = 0A
equity:closing balances 2A equity:closing balances 2A
@ -160,7 +161,7 @@ $ hledger -f- close assets -p 2019
# 7. With --show-costs, the transaction prices are preserved. # 7. With --show-costs, the transaction prices are preserved.
# Only the last posting in each commodity gets a balance assertion (#1035). # Only the last posting in each commodity gets a balance assertion (#1035).
# Balance assertion amounts do not have a price. # Balance assertion amounts do not have a price.
$ hledger -f- close assets -p 2019 --show-costs $ hledger -f- close assets -p 2019 --show-costs -x
2019-12-31 closing balances 2019-12-31 closing balances
assets -1A @ 1B assets -1A @ 1B
assets -1A @ 1C = 0A assets -1A @ 1C = 0A
@ -184,7 +185,7 @@ $ hledger -f- close assets -p 2019 --show-costs
2019/01/02 2019/01/02
(assets) 1A @ 2B (assets) 1A @ 2B
$ hledger -f- close assets -p 2019 $ hledger -f- close assets -p 2019 -x
2019-12-31 closing balances 2019-12-31 closing balances
assets -2A = 0A assets -2A = 0A
equity:closing balances 2A equity:closing balances 2A
@ -203,7 +204,7 @@ $ hledger -f- close assets -p 2019
2019/01/02 2019/01/02
(assets) 1A @ 2B (assets) 1A @ 2B
$ hledger -f- close assets -p 2019 --show-costs $ hledger -f- close assets -p 2019 --show-costs -x
2019-12-31 closing balances 2019-12-31 closing balances
assets -1A @ 1B assets -1A @ 1B
assets -1A @ 2B = 0A assets -1A @ 2B = 0A
@ -242,7 +243,7 @@ $ hledger -f- close assets -p 2019 --show-costs
assets:bank 2,836.00 EUR assets:bank 2,836.00 EUR
liabilities:employer liabilities:employer
$ hledger -f- close -p 2016 assets liabilities --show-costs $ hledger -f- close -p 2016 assets liabilities --show-costs -x
2016-12-31 closing balances 2016-12-31 closing balances
assets:bank -5,733.00 EUR = 0.00 EUR assets:bank -5,733.00 EUR = 0.00 EUR
liabilities:employer $-10,000.00 liabilities:employer $-10,000.00
@ -270,7 +271,7 @@ $ hledger -f- close -p 2016 assets liabilities --show-costs
# 11. With --interleaved, each transfer's postings are adjacent. # 11. With --interleaved, each transfer's postings are adjacent.
# (And balances with the same cost are not necessarily combined into # (And balances with the same cost are not necessarily combined into
# a single posting. Eg the 5734 EUR above is 5733 EUR and 1 EUR below.) # a single posting. Eg the 5734 EUR above is 5733 EUR and 1 EUR below.)
$ hledger -f- close -p 2016 assets liabilities --interleaved --show-costs $ hledger -f- close -p 2016 assets liabilities --interleaved --show-costs -x
2016-12-31 closing balances 2016-12-31 closing balances
assets:bank -5,733.00 EUR = 0.00 EUR assets:bank -5,733.00 EUR = 0.00 EUR
equity:closing balances 5,733.00 EUR equity:closing balances 5,733.00 EUR
@ -311,7 +312,7 @@ commodity AAA 0.00000000
assets:usd -$0.1280810 assets:usd -$0.1280810
expenses:banking $0.1280810 expenses:banking $0.1280810
$ hledger -f- close -p 2019 assets --show-costs $ hledger -f- close -p 2019 assets --show-costs -x
2019-12-31 closing balances 2019-12-31 closing balances
assets:aaa AAA -510.00000000 = AAA 0.00000000 assets:aaa AAA -510.00000000 = AAA 0.00000000
assets:usd $-49.50 assets:usd $-49.50
@ -331,7 +332,7 @@ $ hledger -f- close -p 2019 assets --show-costs
>=0 >=0
# 13. The same, without costs and with --interleaved. # 13. The same, without costs and with --interleaved.
$ hledger -f- close -p 2019 assets --interleaved $ hledger -f- close -p 2019 assets --interleaved -x
2019-12-31 closing balances 2019-12-31 closing balances
assets:aaa AAA -510.00000000 = AAA 0.00000000 assets:aaa AAA -510.00000000 = AAA 0.00000000
equity:closing balances AAA 510.00000000 equity:closing balances AAA 510.00000000