mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-26 20:02:27 +03:00
doc: test: update for commodity-column
Add documentation and sample output for `--commodity-column` behavior and functional tests e.g single-period balance, yearly balance, and yearly budget
This commit is contained in:
parent
198d2211fc
commit
234caae557
@ -34,7 +34,7 @@ instance Monoid WideBuilder where
|
||||
wbToText :: WideBuilder -> Text
|
||||
wbToText = TL.toStrict . TB.toLazyText . wbBuilder
|
||||
|
||||
-- | Convert a WideBuilder to a strict Text.
|
||||
-- | Convert a strict Text to a WideBuilder.
|
||||
wbFromText :: Text -> WideBuilder
|
||||
wbFromText t = WideBuilder (TB.fromText t) (textWidth t)
|
||||
|
||||
|
@ -311,7 +311,7 @@ balancemode = hledgerCommandMode
|
||||
,flagNone ["invert"] (setboolopt "invert") "display all amounts with reversed sign"
|
||||
,flagNone ["transpose"] (setboolopt "transpose") "transpose rows and columns"
|
||||
,flagNone ["commodity-column"] (setboolopt "commodity-column")
|
||||
"shows each commodity in its own automatically-generated subaccount, for tidier reports"
|
||||
"shows one row per commodity and puts the commodity symbol in its own column, leaving amounts as bare numbers"
|
||||
,outputFormatFlag ["txt","html","csv","json"]
|
||||
,outputFileFlag
|
||||
]
|
||||
|
@ -64,6 +64,7 @@ Many of these work with the higher-level commands as well.
|
||||
- rows and columns swapped ([`--transpose`](#multi-period-balance-report))
|
||||
- another field used as account name ([`--pivot`](#multi-period-balance-report))
|
||||
- custom-formatted line items (single-period reports only) ([`--format`](#customising-single-period-balance-reports))
|
||||
- commodities shown in a separate column, one per row ([`--commodity-column`](#commodity-column))
|
||||
|
||||
This command supports the
|
||||
[output destination](#output-destination) and
|
||||
@ -255,6 +256,63 @@ Here are some ways to handle that:
|
||||
[csv-mode]: https://elpa.gnu.org/packages/csv-mode.html
|
||||
[visidata]: https://www.visidata.org
|
||||
|
||||
#### commodity column
|
||||
|
||||
With `--commodity-column`, each commodity of an account is displayed as a
|
||||
separate row item row will only include the quantity. The commodity itself is
|
||||
shown as a separate column, one per row. This can be useful for a cleaner
|
||||
display of multi-period reports with many commodities
|
||||
|
||||
```shell
|
||||
$ hledger bal -T -Y
|
||||
Balance changes in 2012-01-01..2014-12-31:
|
||||
|
||||
|| 2012 2013 2014 Total
|
||||
==================++=============================================================================================================================
|
||||
Assets:US:ETrade || 10.00 ITOT, 337.18 USD, 2 more.. 70.00 GLD, 18.00 ITOT, 3 more.. -11.00 ITOT, 3 more.. 70.00 GLD, 17.00 ITOT, 3 more..
|
||||
------------------++-----------------------------------------------------------------------------------------------------------------------------
|
||||
total || 10.00 ITOT, 337.18 USD, 2 more.. 70.00 GLD, 18.00 ITOT, 3 more.. -11.00 ITOT, 3 more.. 70.00 GLD, 17.00 ITOT, 3 more..
|
||||
|
||||
$ hledger bal -T -Y --commodity-column
|
||||
Balance changes in 2012-01-01..2014-12-31:
|
||||
|
||||
|| Commodity 2012 2013 2014 Total
|
||||
==================++=============================================
|
||||
Assets:US:ETrade || GLD 0 70.00 0 70.00
|
||||
Assets:US:ETrade || ITOT 10.00 18.00 -11.00 17.00
|
||||
Assets:US:ETrade || USD 337.18 -98.12 4881.44 5120.50
|
||||
Assets:US:ETrade || VEA 12.00 10.00 14.00 36.00
|
||||
Assets:US:ETrade || VHT 106.00 18.00 170.00 294.00
|
||||
------------------++---------------------------------------------
|
||||
|| GLD 0 70.00 0 70.00
|
||||
|| ITOT 10.00 18.00 -11.00 17.00
|
||||
|| USD 337.18 -98.12 4881.44 5120.50
|
||||
|| VEA 12.00 10.00 14.00 36.00
|
||||
|| VHT 106.00 18.00 170.00 294.00
|
||||
```
|
||||
|
||||
Single-period CSV balance reports also follow this new convention.
|
||||
|
||||
```shell
|
||||
$ hledger bal -T -O csv
|
||||
"account","balance"
|
||||
"Assets:US:ETrade","70.00 GLD, 17.00 ITOT, 5120.50 USD, 36.00 VEA, 294.00 VHT"
|
||||
"total","70.00 GLD, 17.00 ITOT, 5120.50 USD, 36.00 VEA, 294.00 VHT"
|
||||
|
||||
$ hledger bal -T -O csv --commodity-column
|
||||
"account","commodity","balance"
|
||||
"Assets:US:ETrade","GLD","70.00"
|
||||
"Assets:US:ETrade","ITOT","17.00"
|
||||
"Assets:US:ETrade","USD","5120.50"
|
||||
"Assets:US:ETrade","VEA","36.00"
|
||||
"Assets:US:ETrade","VHT","294.00"
|
||||
"total","GLD","70.00"
|
||||
"total","ITOT","17.00"
|
||||
"total","USD","5120.50"
|
||||
"total","VEA","36.00"
|
||||
"total","VHT","294.00"
|
||||
```
|
||||
|
||||
### Sorting by amount
|
||||
|
||||
With `-S/--sort-amount`, accounts with the largest (most positive) balances are shown first.
|
||||
|
104
hledger/test/balance/commodity-account.test
Normal file
104
hledger/test/balance/commodity-account.test
Normal file
@ -0,0 +1,104 @@
|
||||
# Record a complicated real-life example. Layout is not perfect, but any
|
||||
# changes should be noted and evaluated whether they improve things.
|
||||
|
||||
$ hledger -f bcexample.hledger bal assets.*etrade -3 -O csv
|
||||
>
|
||||
"account","balance"
|
||||
"Assets:US:ETrade","70.00 GLD, 17.00 ITOT, 5120.50 USD, 36.00 VEA, 294.00 VHT"
|
||||
"total","70.00 GLD, 17.00 ITOT, 5120.50 USD, 36.00 VEA, 294.00 VHT"
|
||||
>=0
|
||||
|
||||
$ hledger -f bcexample.hledger bal assets.*etrade -3 -O csv --commodity-column
|
||||
>
|
||||
"account","commodity","balance"
|
||||
"Assets:US:ETrade","GLD","70.00"
|
||||
"Assets:US:ETrade","ITOT","17.00"
|
||||
"Assets:US:ETrade","USD","5120.50"
|
||||
"Assets:US:ETrade","VEA","36.00"
|
||||
"Assets:US:ETrade","VHT","294.00"
|
||||
"total","GLD","70.00"
|
||||
"total","ITOT","17.00"
|
||||
"total","USD","5120.50"
|
||||
"total","VEA","36.00"
|
||||
"total","VHT","294.00"
|
||||
>=0
|
||||
|
||||
$ hledger -f bcexample.hledger bal assets.*etrade -3
|
||||
>
|
||||
70.00 GLD
|
||||
17.00 ITOT
|
||||
5120.50 USD
|
||||
36.00 VEA
|
||||
294.00 VHT Assets:US:ETrade
|
||||
--------------------
|
||||
70.00 GLD
|
||||
17.00 ITOT
|
||||
5120.50 USD
|
||||
36.00 VEA
|
||||
294.00 VHT
|
||||
>=0
|
||||
|
||||
$ hledger -f bcexample.hledger bal assets.*etrade -3 --commodity-column
|
||||
>
|
||||
70.00 GLD
|
||||
17.00 ITOT
|
||||
5120.50 USD
|
||||
36.00 VEA
|
||||
294.00 VHT Assets:US:ETrade
|
||||
-------
|
||||
70.00 GLD
|
||||
17.00 ITOT
|
||||
5120.50 USD
|
||||
36.00 VEA
|
||||
294.00 VHT
|
||||
>=0
|
||||
|
||||
$ hledger -f bcexample.hledger bal -T -Y assets.*etrade -3 -O csv
|
||||
>
|
||||
"account","2012","2013","2014","total"
|
||||
"Assets:US:ETrade","10.00 ITOT, 337.18 USD, 12.00 VEA, 106.00 VHT","70.00 GLD, 18.00 ITOT, -98.12 USD, 10.00 VEA, 18.00 VHT","-11.00 ITOT, 4881.44 USD, 14.00 VEA, 170.00 VHT","70.00 GLD, 17.00 ITOT, 5120.50 USD, 36.00 VEA, 294.00 VHT"
|
||||
"total","10.00 ITOT, 337.18 USD, 12.00 VEA, 106.00 VHT","70.00 GLD, 18.00 ITOT, -98.12 USD, 10.00 VEA, 18.00 VHT","-11.00 ITOT, 4881.44 USD, 14.00 VEA, 170.00 VHT","70.00 GLD, 17.00 ITOT, 5120.50 USD, 36.00 VEA, 294.00 VHT"
|
||||
>=0
|
||||
|
||||
$ hledger -f bcexample.hledger bal -T -Y assets.*etrade -3 -O csv --commodity-column
|
||||
>
|
||||
"account","commodity","2012","2013","2014","total"
|
||||
"Assets:US:ETrade","GLD","0","70.00","0","70.00"
|
||||
"Assets:US:ETrade","ITOT","10.00","18.00","-11.00","17.00"
|
||||
"Assets:US:ETrade","USD","337.18","-98.12","4881.44","5120.50"
|
||||
"Assets:US:ETrade","VEA","12.00","10.00","14.00","36.00"
|
||||
"Assets:US:ETrade","VHT","106.00","18.00","170.00","294.00"
|
||||
"total","GLD","0","70.00","0","70.00"
|
||||
"total","ITOT","10.00","18.00","-11.00","17.00"
|
||||
"total","USD","337.18","-98.12","4881.44","5120.50"
|
||||
"total","VEA","12.00","10.00","14.00","36.00"
|
||||
"total","VHT","106.00","18.00","170.00","294.00"
|
||||
>=0
|
||||
|
||||
$ hledger -f bcexample.hledger bal -Y assets.*etrade -3 --average --commodity-column --no-total
|
||||
>
|
||||
Balance changes in 2012-01-01..2014-12-31:
|
||||
|
||||
|| Commodity 2012 2013 2014 Average
|
||||
==================++=============================================
|
||||
Assets:US:ETrade || GLD 0 70.00 0 23.33
|
||||
Assets:US:ETrade || ITOT 10.00 18.00 -11.00 5.67
|
||||
Assets:US:ETrade || USD 337.18 -98.12 4881.44 1706.83
|
||||
Assets:US:ETrade || VEA 12.00 10.00 14.00 12.00
|
||||
Assets:US:ETrade || VHT 106.00 18.00 170.00 98.00
|
||||
>=0
|
||||
|
||||
$ hledger -f bcexample.hledger bal -Y assets.*etrade -3 -O csv --commodity-column --budget
|
||||
>
|
||||
"Account","Commodity","2012","budget","2013","budget","2014","budget"
|
||||
"<unbudgeted>","GLD","0","0","70.00","0","0","0"
|
||||
"<unbudgeted>","ITOT","10.00","0","18.00","0","-11.00","0"
|
||||
"<unbudgeted>","USD","337.18","0","-98.12","0","4881.44","0"
|
||||
"<unbudgeted>","VEA","12.00","0","10.00","0","14.00","0"
|
||||
"<unbudgeted>","VHT","106.00","0","18.00","0","170.00","0"
|
||||
"Total:","GLD","0","0","70.00","0","0","0"
|
||||
"Total:","ITOT","10.00","0","18.00","0","-11.00","0"
|
||||
"Total:","USD","337.18","0","-98.12","0","4881.44","0"
|
||||
"Total:","VEA","12.00","0","10.00","0","14.00","0"
|
||||
"Total:","VHT","106.00","0","18.00","0","170.00","0"
|
||||
>=0
|
Loading…
Reference in New Issue
Block a user