hledger/tests/budget/budget.test
Simon Michael 3d4f5600ae journal: infer and balance amounts with standard amount styles (fix #737)
Inferred amounts now have the appropriate standard amount style applied.
And when checking for balanced transactions, amount styles declared with
commodity directives are also used (previously only inferred amount styles were).
2018-04-20 13:40:05 -07:00

265 lines
8.7 KiB
Plaintext

# balance --budget tests
2016/12/01
expenses:food $10
assets:cash
2016/12/02
expenses:food $9
assets:cash
2016/12/03
expenses:food $11
assets:cash
2016/12/02
expenses:leisure $5
assets:cash
2016/12/03
expenses:movies $25
assets:cash
2016/12/03
expenses:cab $15
assets:cash
~ daily from 2016/1/1
expenses:food $10
expenses:leisure $15
assets:cash
# 1. Test --budget switch
$ hledger bal -D -b 2016-12-01 -e 2016-12-04 -f - --budget
Balance changes in 2016/12/01-2016/12/03:
|| 2016/12/01 2016/12/02 2016/12/03
=======================++==============================================================================
<unbudgeted>:expenses || 0 0 $40
assets:cash || $-10 [ 40% of $-25] $-14 [ 56% of $-25] $-51 [ 204% of $-25]
expenses:food || $10 [ 100% of $10] $9 [ 90% of $10] $11 [ 110% of $10]
expenses:leisure || 0 [ 0% of $15] $5 [ 33% of $15] 0 [ 0% of $15]
-----------------------++------------------------------------------------------------------------------
|| 0 [ 0% of 0] 0 [ 0% of 0] 0 [ 0% of 0]
# 2. --show-unbudgeted
$ hledger bal -D -b 2016-12-01 -e 2016-12-04 -f - --budget --show-unbudgeted
Balance changes in 2016/12/01-2016/12/03:
|| 2016/12/01 2016/12/02 2016/12/03
==================++==============================================================================
assets:cash || $-10 [ 40% of $-25] $-14 [ 56% of $-25] $-51 [ 204% of $-25]
expenses:cab || 0 0 $15
expenses:food || $10 [ 100% of $10] $9 [ 90% of $10] $11 [ 110% of $10]
expenses:leisure || 0 [ 0% of $15] $5 [ 33% of $15] 0 [ 0% of $15]
expenses:movies || 0 0 $25
------------------++------------------------------------------------------------------------------
|| 0 [ 0% of 0] 0 [ 0% of 0] 0 [ 0% of 0]
# 3. Test that budget works with mix of commodities
<
2016/12/01
expenses:food £10 @@ $15
assets:cash
2016/12/02
expenses:food 10 CAD @ $1
assets:cash
2016/12/02
expenses:food 10 CAD @ $1.1
assets:cash
2016/12/03
expenses:food $11
assets:cash
2016/12/02
expenses:leisure $5
assets:cash
2016/12/03
expenses:movies $25
assets:cash
2016/12/03
expenses:cab $15
assets:cash
~ daily from 2016/1/1
expenses:food $10
expenses:leisure $15
assets:cash
$ hledger bal -D -b 2016-12-01 -e 2016-12-04 -f - --budget
Balance changes in 2016/12/01-2016/12/03:
|| 2016/12/01 2016/12/02 2016/12/03
=======================++=====================================================================================
<unbudgeted>:expenses || 0 0 $40
assets:cash || $-15 [ 60% of $-25] $-26 [ 104% of $-25] $-51 [ 204% of $-25]
expenses:food || £10 [ 150% of $10] 20 CAD [ 210% of $10] $11 [ 110% of $10]
expenses:leisure || 0 [ 0% of $15] $5 [ 33% of $15] 0 [ 0% of $15]
-----------------------++-------------------------------------------------------------------------------------
|| $-15, £10 [ 0% of 0] $-21, 20 CAD [ 0% of 0] 0 [ 0% of 0]
# TODO zero totals ^
<
~ daily
(a) 10
~weekly
(b) 100
~weekly
(c) 1000
2018/1/1
(a) 1
(b) 1
(c) 1
2018/1/3
(a) 1
(b) 1
(c) 1
# 4. --budget uses only periodic transactions of the specified interval.
# No interval - same as a regular balance report.
$ hledger -f- bal --budget
2 a
2 b
2 c
--------------------
6
# 5. With -D it selects the daily budget.
# The budget is unbounded, so extends through the report period.
$ hledger -f- bal --budget -D
Balance changes in 2018/01/01-2018/01/03:
|| 2018/01/01 2018/01/02 2018/01/03
===++==============================================================================
a || 1 [ 10% of 10] 0 [ 0% of 10] 1 [ 10% of 10]
b || 1 0 1
c || 1 0 1
---++------------------------------------------------------------------------------
|| 3 [ 30% of 10] 0 [ 0% of 10] 3 [ 30% of 10]
# TODO misleading totals ? ^
# 6. And with -W it selects the weekly budget, defined by all weekly periodic transactions.
$ hledger -f- bal --budget -W
Balance changes in 2018/01/01w01:
|| 2018/01/01w01
===++==========================
a || 2
b || 2 [ 2% of 100]
c || 2 [ 0% of 1000]
---++--------------------------
|| 6 [ 1% of 1100]
# 7. A bounded two day budget. The end date is exclusive as usual.
<
~ daily from 2018/1/2 to 2018/1/4
(a) 1
2018/1/1
(a) 1
(b) 1
2018/1/2
(a) 1
(b) 1
2018/1/3
(a) 1
(b) 1
2018/1/4
(a) 1
(b) 1
$ hledger -f- bal --budget -D
Balance changes in 2018/01/01-2018/01/04:
|| 2018/01/01 2018/01/02 2018/01/03 2018/01/04
================++========================================================================================================
<unbudgeted>:b || 1 1 1 1
a || 1 1 [ 100% of 1] 1 [ 100% of 1] 1
----------------++--------------------------------------------------------------------------------------------------------
|| 2 2 [ 200% of 1] 2 [ 200% of 1] 2
# 8. Multiple bounded budgets.
<
~ daily from 2018/1/1 to 2018/1/3
(a) 1
~ daily from 2018/1/3 to 2018/1/5
(a) 10
2018/1/1
(a) 1
2018/1/2
(a) 1
2018/1/3
(a) 1
2018/1/4
(a) 1
$ hledger -f- bal --budget -D
Balance changes in 2018/01/01-2018/01/04:
|| 2018/01/01 2018/01/02 2018/01/03 2018/01/04
===++========================================================================================================
a || 1 [ 100% of 1] 1 [ 100% of 1] 1 [ 10% of 10] 1 [ 10% of 10]
---++--------------------------------------------------------------------------------------------------------
|| 1 [ 100% of 1] 1 [ 100% of 1] 1 [ 10% of 10] 1 [ 10% of 10]
# 9. A "from A to B" budget should not be included in a report beginning on B.
$ hledger -f- bal --budget -D -b 2018/1/3
Balance changes in 2018/01/03-2018/01/04:
|| 2018/01/03 2018/01/04
===++====================================================
a || 1 [ 10% of 10] 1 [ 10% of 10]
---++----------------------------------------------------
|| 1 [ 10% of 10] 1 [ 10% of 10]
<
~ daily
(a) 1
2018/1/2
(a) 2
2018/1/2
(a) -2
# 10. accounts with non-zero budget should be shown by default
# even if there are no actual transactions in the period,
# or if the actual amount is zero.
# $ hledger -f- bal --budget -D date:2018/1/1-2018/1/3
# Balance changes in 2018/01/01-2018/01/02:
# || 2018/01/01 2018/01/02
# ===++====================================================
# a || [ 1] [ 1]
# ---++----------------------------------------------------
# || [ 1] [ 1]
# 11. With -E, zeroes are shown
$ hledger -f- bal --budget -D date:2018/1/1-2018/1/3 -E
Balance changes in 2018/01/01-2018/01/02:
|| 2018/01/01 2018/01/02
===++====================================================
a || 0 [ 0% of 1] 0 [ 0% of 1]
---++----------------------------------------------------
|| 0 [ 0% of 1] 0 [ 0% of 1]