hledger/tests/journal/auto-postings.test

330 lines
9.8 KiB
Plaintext

# Transaction modifier adding (unbalanced) tax postings.
# print. Auto-generated postings are inserted below the matched one.
<
= ^income
(liabilities:tax) *.33 ; income tax
2016/1/1 paycheck
income:remuneration $-100
income:donations $-15
assets:bank
2016/1/1 withdraw
assets:cash $20
assets:bank
# 1. print
$ hledger print -f- --auto
2016/01/01 paycheck ; modified:
income:remuneration $-100
(liabilities:tax) $-33 ; income tax, generated-posting: = ^income
income:donations $-15
(liabilities:tax) $-5 ; income tax, generated-posting: = ^income
assets:bank
2016/01/01 withdraw
assets:cash $20
assets:bank
>=
# 2. register
$ hledger register -f- --auto
2016/01/01 paycheck income:remuneration $-100 $-100
(liabilities:tax) $-33 $-133
income:donations $-15 $-148
(liabilities:tax) $-5 $-153
assets:bank $115 $-38
2016/01/01 withdraw assets:cash $20 $-18
assets:bank $-20 $-38
>=
# 3. balance
$ hledger balance -f- --auto
$115 assets
$95 bank
$20 cash
$-115 income
$-15 donations
$-100 remuneration
$-38 liabilities:tax
--------------------
$-38
>=
# Balance assertions see postings generated by transaction modifier rules.
<
= trigger
(target) 10
2018/1/1
(trigger) 1
(target) 1 = 11 ; this assertion would not fail, auto posting will be taken into account
# 4.
$ hledger register -f- --auto
2018/01/01 (trigger) 1 1
(target) 10 11
(target) 1 12
>=
# Transaction modifier adding (balanced virtual) budget envelope postings.
<
= ^expenses:groceries
[budget:groceries] *-1
[assets:bank:checking] *1
2018/10/7 * MARKET
expenses:groceries:food
assets:bank:checking $-20
# 5.
$ hledger print -f- --auto
2018/10/07 * MARKET ; modified:
expenses:groceries:food
[budget:groceries] $-20 ; generated-posting: = ^expenses:groceries
[assets:bank:checking] $20 ; generated-posting: = ^expenses:groceries
assets:bank:checking $-20
>=
# Rules will preserve a transaction price from the original amount.
<
= assets:billable:client1
assets:receivable:client1 *100
revenues:client1
2018/1/1
(assets:billable:client1) 0.50h @ $90
# 6.
$ hledger -f- print --auto -x
2018/01/01 ; modified:
(assets:billable:client1) 0.50h @ $90
assets:receivable:client1 50.00h @ $90 ; generated-posting: = assets:billable:client1
revenues:client1 $-4500 ; generated-posting: = assets:billable:client1
>=
# Rules can set a new commodity in the generated amounts.
<
= assets:billable:client1
assets:receivable:client1 *$100
revenues:client1
2018/1/1
(assets:billable:client1) 0.50h
# 7.
$ hledger -f- print --auto -x
2018/01/01 ; modified:
(assets:billable:client1) 0.50h
assets:receivable:client1 $50 ; generated-posting: = assets:billable:client1
revenues:client1 $-50 ; generated-posting: = assets:billable:client1
>=
# And/or a new transaction price.
<
= assets:billable:client1
assets:receivable:client1 *1.00 "Client1 Hours" @ $100.00
revenues:client1
2018/1/1
(assets:billable:client1) 0.50h @ $90
# 8.
$ hledger -f- print --auto -x
2018/01/01 ; modified:
(assets:billable:client1) 0.50h @ $90
assets:receivable:client1 0.50 "Client1 Hours" @ $100.00 ; generated-posting: = assets:billable:client1
revenues:client1 $-50.00 ; generated-posting: = assets:billable:client1
>=
# Balance assignments may not be used with accounts also affected by transaction modifier rules.
<
= ^expenses:foo
budget:available *-1
assets:checking *1
2018/10/17 * INITIAL
budget:available $100
equity:opening
2018/10/17 * SOME EXPENSE
expenses:foo $50
assets:checking
2018/10/17 * ASSERT
budget:other
budget:available =$0
# 9.
$ hledger print -f- --auto
>2 /cannot be used with accounts which are/
>=1
# Issue #928:
# Generating auto postings from a unit-priced amount.
<
= ^Expenses:Joint
Expenses:Joint *-1
Liabilities:Joint:Bob *0.5
Liabilities:Joint:Bill *0.5
2018/01/01
Expenses:Joint:Widgets $100.00 @ £0.50
Assets:Joint:Bank -£50.00
# 10.
$ hledger -f- print --auto
2018/01/01 ; modified:
Expenses:Joint:Widgets $100.00 @ £0.50
Expenses:Joint $-100.00 @ £0.50 ; generated-posting: = ^Expenses:Joint
Liabilities:Joint:Bob $50.00 @ £0.50 ; generated-posting: = ^Expenses:Joint
Liabilities:Joint:Bill $50.00 @ £0.50 ; generated-posting: = ^Expenses:Joint
Assets:Joint:Bank £-50.00
>=0
# Generating auto postings from a total-priced amount.
<
= ^Expenses:Joint
Expenses:Joint *-1
Liabilities:Joint:Bob *0.5
Liabilities:Joint:Bill *0.5
2018/01/01
Expenses:Joint:Widgets $100.00 @@ £50
Assets:Joint:Bank -£50.00
# 11.
$ hledger -f- print --auto
2018/01/01 ; modified:
Expenses:Joint:Widgets $100.00 @@ £50
Expenses:Joint $-100.00 @@ £50 ; generated-posting: = ^Expenses:Joint
Liabilities:Joint:Bob $50.00 @@ £25 ; generated-posting: = ^Expenses:Joint
Liabilities:Joint:Bill $50.00 @@ £25 ; generated-posting: = ^Expenses:Joint
Assets:Joint:Bank £-50.00
>=0
# alternate approach: convert to unit prices
#2018/01/01
# Expenses:Joint:Widgets $100.00 @@ £50
# Expenses:Joint $-100.00 @ £0.5
# Liabilities:Joint:Bob $50.00 @ £0.5
# Liabilities:Joint:Bill $50.00 @ £0.5
# Assets:Joint:Bank £-50.00
# Generating auto postings from an implicitly-priced amount. Should work like the above.
<
= ^Expenses:Joint
Expenses:Joint *-1
Liabilities:Joint:Bob *0.5
Liabilities:Joint:Bill *0.5
2018/01/01
Expenses:Joint:Widgets $100.00
Assets:Joint:Bank -£50.00
# 12.
$ hledger -f- print --auto
2018/01/01 ; modified:
Expenses:Joint:Widgets $100.00
Expenses:Joint $-100.00 @@ £50 ; generated-posting: = ^Expenses:Joint
Liabilities:Joint:Bob $50.00 @@ £25 ; generated-posting: = ^Expenses:Joint
Liabilities:Joint:Bill $50.00 @@ £25 ; generated-posting: = ^Expenses:Joint
Assets:Joint:Bank £-50.00
>=0
#
## Transaction modifiers affect forecast transactions (#959)
<
= ^income
(liabilities:tax) *.33 ; income tax
~ monthly from 2016-01 paycheck
income:remuneration $-100
income:donations $-15
assets:bank
2016/1/3 withdraw
assets:cash $20
assets:bank
# 13.
$ hledger print -f- --auto --forecast -b 2016-01 -e 2016-03
2016/01/03 withdraw
assets:cash $20
assets:bank
2016/02/01 paycheck
; generated-transaction: ~ monthly from 2016-01, modified:
income:remuneration $-100
(liabilities:tax) $-33 ; income tax, generated-posting: = ^income
income:donations $-15
(liabilities:tax) $-5 ; income tax, generated-posting: = ^income
assets:bank
>=
# 14. and they don't force --auto on
$ hledger print -f- --forecast -b 2016-01 -e 2016-03
2016/01/03 withdraw
assets:cash $20
assets:bank
2016/02/01 paycheck
; generated-transaction: ~ monthly from 2016-01
income:remuneration $-100
income:donations $-15
assets:bank
>=
# #893a
<
= ^expenses:groceries
[budget:groceries] *-1
[assets:bank:checking] *1
10/7 * MARKET
expenses:groceries:food
assets:bank:checking $-20
# 15.
$ hledger -f- register --auto
2019/10/07 MARKET ex:groceries:food $20 $20
[budget:groceries] $-20 0
[as:bank:checking] $20 $20
assets:bank:checking $-20 0
>=
# #893b, https://github.com/simonmichael/hledger/issues/893#issuecomment-459125266
<
= tag:tax20
taxes *0.2
2018/12/18
a EUR -10.00 ; :tax20:
b EUR 12.00
# 16. Transaction balancing sees auto postings ?
# $ hledger -f- print -x --auto
# 2018/12/18
# a EUR -10.00 ; :tax20:
# taxes EUR -2.00
# b EUR 12.00
#
# >=
# 16. No, transaction must be balanced both with and without auto postings.
$ hledger -f- print -x --auto
>2 /could not balance/
>=1