hledger/tests/balancesheet.test
Simon Michael c2929939e4 make account type autodetection (& hledger-smooth) case insensitive again (#1341)
lib: added case-insensitive variants of the accountNameToRegex functions.
2020-09-03 09:52:00 -07:00

308 lines
20 KiB
Plaintext

# 1. A trivial balance sheet. With no accounts of type Asset declared,
# a top-level "assets" account is autodetected as an Asset.
<
2016/1/1
assets 1
b
$ hledger -f - balancesheet
Balance Sheet 2016-01-01
|| 2016-01-01
=============++============
Assets ||
-------------++------------
assets || 1
-------------++------------
|| 1
=============++============
Liabilities ||
-------------++------------
-------------++------------
||
=============++============
Net: || 1
# 2. Account type autodetection is case insensitive.
<
2016/1/1
ASSETS 1
b
$ hledger -f - balancesheet
Balance Sheet 2016-01-01
|| 2016-01-01
=============++============
Assets ||
-------------++------------
ASSETS || 1
-------------++------------
|| 1
=============++============
Liabilities ||
-------------++------------
-------------++------------
||
=============++============
Net: || 1
# 3. monthly balance sheet, normal positive sign
# old (arithmetic sign):
#Balance Sheet
#
# || 2008/01/31 2008/02/29 2008/03/31 2008/04/30 2008/05/31 2008/06/30 2008/07/31 2008/08/31 2008/09/30 2008/10/31 2008/11/30 2008/12/31
#======================++================================================================================================================================================
# Assets ||
#----------------------++------------------------------------------------------------------------------------------------------------------------------------------------
# assets:bank:checking || $1 $1 $1 $1 $1 $1 $1 $1 $1 $1 $1 0
# assets:bank:saving || 0 0 0 0 0 $1 $1 $1 $1 $1 $1 $1
# assets:cash || 0 0 0 0 0 $-2 $-2 $-2 $-2 $-2 $-2 $-2
#----------------------++------------------------------------------------------------------------------------------------------------------------------------------------
# || $1 $1 $1 $1 $1 0 0 0 0 0 0 $-1
#======================++================================================================================================================================================
# Liabilities ||
#----------------------++------------------------------------------------------------------------------------------------------------------------------------------------
# liabilities:debts || 0 0 0 0 0 0 0 0 0 0 0 $1
#----------------------++------------------------------------------------------------------------------------------------------------------------------------------------
# || 0 0 0 0 0 0 0 0 0 0 0 $1
#======================++================================================================================================================================================
# Total || $1 $1 $1 $1 $1 0 0 0 0 0 0 0
#
$ hledger -f sample.journal balancesheet -p 'monthly in 2008'
Balance Sheet 2008-01-31..2008-12-31
|| 2008-01-31 2008-02-29 2008-03-31 2008-04-30 2008-05-31 2008-06-30 2008-07-31 2008-08-31 2008-09-30 2008-10-31 2008-11-30 2008-12-31
======================++================================================================================================================================================
Assets ||
----------------------++------------------------------------------------------------------------------------------------------------------------------------------------
assets:bank:checking || $1 $1 $1 $1 $1 $1 $1 $1 $1 $1 $1 0
assets:bank:saving || 0 0 0 0 0 $1 $1 $1 $1 $1 $1 $1
assets:cash || 0 0 0 0 0 $-2 $-2 $-2 $-2 $-2 $-2 $-2
----------------------++------------------------------------------------------------------------------------------------------------------------------------------------
|| $1 $1 $1 $1 $1 0 0 0 0 0 0 $-1
======================++================================================================================================================================================
Liabilities ||
----------------------++------------------------------------------------------------------------------------------------------------------------------------------------
liabilities:debts || 0 0 0 0 0 0 0 0 0 0 0 $-1
----------------------++------------------------------------------------------------------------------------------------------------------------------------------------
|| 0 0 0 0 0 0 0 0 0 0 0 $-1
======================++================================================================================================================================================
Net: || $1 $1 $1 $1 $1 0 0 0 0 0 0 0
# 4. monthly balance sheet in tree mode
# old (arithmetic sign):
# || 2008/01/31 2008/02/29 2008/03/31 2008/04/30 2008/05/31 2008/06/30 2008/07/31 2008/08/31 2008/09/30 2008/10/31 2008/11/30 2008/12/31
#==============++================================================================================================================================================
# Assets ||
#--------------++------------------------------------------------------------------------------------------------------------------------------------------------
# assets || $1 $1 $1 $1 $1 0 0 0 0 0 0 $-1
# bank || $1 $1 $1 $1 $1 $2 $2 $2 $2 $2 $2 $1
# checking || $1 $1 $1 $1 $1 $1 $1 $1 $1 $1 $1 0
# saving || 0 0 0 0 0 $1 $1 $1 $1 $1 $1 $1
# cash || 0 0 0 0 0 $-2 $-2 $-2 $-2 $-2 $-2 $-2
#--------------++------------------------------------------------------------------------------------------------------------------------------------------------
# || $1 $1 $1 $1 $1 0 0 0 0 0 0 $-1
#==============++================================================================================================================================================
# Liabilities ||
#--------------++------------------------------------------------------------------------------------------------------------------------------------------------
# liabilities || 0 0 0 0 0 0 0 0 0 0 0 $1
# debts || 0 0 0 0 0 0 0 0 0 0 0 $1
#--------------++------------------------------------------------------------------------------------------------------------------------------------------------
# || 0 0 0 0 0 0 0 0 0 0 0 $1
#==============++================================================================================================================================================
# Total || $1 $1 $1 $1 $1 0 0 0 0 0 0 0
#
$ hledger -f sample.journal balancesheet -p 'monthly in 2008' --tree
Balance Sheet 2008-01-31..2008-12-31
|| 2008-01-31 2008-02-29 2008-03-31 2008-04-30 2008-05-31 2008-06-30 2008-07-31 2008-08-31 2008-09-30 2008-10-31 2008-11-30 2008-12-31
===================++================================================================================================================================================
Assets ||
-------------------++------------------------------------------------------------------------------------------------------------------------------------------------
assets || $1 $1 $1 $1 $1 0 0 0 0 0 0 $-1
bank || $1 $1 $1 $1 $1 $2 $2 $2 $2 $2 $2 $1
checking || $1 $1 $1 $1 $1 $1 $1 $1 $1 $1 $1 0
saving || 0 0 0 0 0 $1 $1 $1 $1 $1 $1 $1
cash || 0 0 0 0 0 $-2 $-2 $-2 $-2 $-2 $-2 $-2
-------------------++------------------------------------------------------------------------------------------------------------------------------------------------
|| $1 $1 $1 $1 $1 0 0 0 0 0 0 $-1
===================++================================================================================================================================================
Liabilities ||
-------------------++------------------------------------------------------------------------------------------------------------------------------------------------
liabilities:debts || 0 0 0 0 0 0 0 0 0 0 0 $-1
-------------------++------------------------------------------------------------------------------------------------------------------------------------------------
|| 0 0 0 0 0 0 0 0 0 0 0 $-1
===================++================================================================================================================================================
Net: || $1 $1 $1 $1 $1 0 0 0 0 0 0 0
# 5. monthly balancesheet with average column and without overall totals row.
# Total column is requested but not shown because balancesheet is in historical mode
# by default (shows ending balances).
$ hledger -f sample.journal balancesheet -p 'monthly in 2008' -NAT
Balance Sheet 2008-01-31..2008-12-31
|| 2008-01-31 2008-02-29 2008-03-31 2008-04-30 2008-05-31 2008-06-30 2008-07-31 2008-08-31 2008-09-30 2008-10-31 2008-11-30 2008-12-31 Average
======================++=========================================================================================================================================================
Assets ||
----------------------++---------------------------------------------------------------------------------------------------------------------------------------------------------
assets:bank:checking || $1 $1 $1 $1 $1 $1 $1 $1 $1 $1 $1 0 $1
assets:bank:saving || 0 0 0 0 0 $1 $1 $1 $1 $1 $1 $1 $1
assets:cash || 0 0 0 0 0 $-2 $-2 $-2 $-2 $-2 $-2 $-2 $-1
======================++=========================================================================================================================================================
Liabilities ||
----------------------++---------------------------------------------------------------------------------------------------------------------------------------------------------
liabilities:debts || 0 0 0 0 0 0 0 0 0 0 0 $-1 0
# 6. Tree output still works, #565
<
2017/1/1
(assets:b) 1
$ hledger -f- balancesheet
Balance Sheet 2017-01-01
|| 2017-01-01
=============++============
Assets ||
-------------++------------
assets:b || 1
-------------++------------
|| 1
=============++============
Liabilities ||
-------------++------------
-------------++------------
||
=============++============
Net: || 1
# 7. Flat output still works, #552
<
2017/1/1
(assets:b) 1
$ hledger -f- balancesheet --flat
Balance Sheet 2017-01-01
|| 2017-01-01
=============++============
Assets ||
-------------++------------
assets:b || 1
-------------++------------
|| 1
=============++============
Liabilities ||
-------------++------------
-------------++------------
||
=============++============
Net: || 1
# 8. An empty section does not disrupt the overall totals, #588
<
2017/1/1
(assets) $1
$ hledger -f- balancesheet -YA
Balance Sheet 2017-12-31
|| 2017-12-31 Average
=============++=====================
Assets ||
-------------++---------------------
assets || $1 $1
-------------++---------------------
|| $1 $1
=============++=====================
Liabilities ||
-------------++---------------------
-------------++---------------------
||
=============++=====================
Net: || $1 $1
# 9. --pretty-tables uses unicode chars for borders
<
2016/1/1
assets 1
b
$ hledger -f - balancesheet -M --pretty-tables
Balance Sheet 2016-01-31
║ 2016-01-31
═════════════╬════════════
Assets ║
─────────────╫────────────
assets ║ 1
─────────────╫────────────
║ 1
═════════════╬════════════
Liabilities ║
─────────────╫────────────
─────────────╫────────────
═════════════╬════════════
Net: ║ 1
# 10. Check that accounts brought to zero by subaccount balances
# are not erased from balancesheet
<
2018-10-01
income:whatever
assets:bank $100
assets:bank:subaccount $10
assets:bank:this subaccount should disappear $10
2018-10-02
assets:bank:this subaccount should disappear -$10
assets:bank
2018-10-03
assets:this account should not disappear:subaccount -$10
assets:this account should not disappear
$ hledger -f - balancesheet --tree
Balance Sheet 2018-10-03
|| 2018-10-03
=====================================++============
Assets ||
-------------------------------------++------------
assets || $120
bank || $120
subaccount || $10
this account should not disappear || 0
subaccount || $-10
-------------------------------------++------------
|| $120
=====================================++============
Liabilities ||
-------------------------------------++------------
-------------------------------------++------------
||
=====================================++============
Net: || $120
# 11. Check that starting balances are also filtered by subreport query. (See issue #1335)
<
2020-03-01 * Rent
assets:a -$1
expenses
2020-03-25 * Salary
assets:a $2
income
$ hledger -f - balancesheet --begin 2020-03-02
Balance Sheet 2020-03-25
|| 2020-03-25
=============++============
Assets ||
-------------++------------
assets:a || $1
-------------++------------
|| $1
=============++============
Liabilities ||
-------------++------------
-------------++------------
||
=============++============
Net: || $1