hledger/tests/journal/transaction-prices.test

247 lines
5.6 KiB
Plaintext
Raw Normal View History

# price-related tests
# 1. print a transaction with an explicit unit price
hledger -f- print --explicit
<<<
2011/01/01
expenses:foreign currency €100 @ $1.35
assets
>>>
2011/01/01
expenses:foreign currency €100 @ $1.35
assets $-135.00
>>>=0
# 2. -B/--cost converts to the price's commodity ("cost")
hledger -f- print --explicit --cost
<<<
2011/01/01
expenses:foreign currency €100 @ $1.35
assets
>>>
2011/01/01
expenses:foreign currency $135.00
assets $-135.00
>>>=0
2015-11-22 19:37:02 +03:00
# 3. print a transaction with a total price
hledger -f - print --explicit
<<<
2011/01/01
expenses:foreign currency €100 @@ $135
assets
>>>
2011/01/01
expenses:foreign currency €100 @@ $135
assets $-135
>>>=0
2015-11-22 19:37:02 +03:00
# 4. when the balance has exactly two commodities, both unpriced, infer an
# implicit conversion price for the first one in terms of the second.
hledger -f - print --explicit
<<<
2011/01/01
expenses:foreign currency €100
misc $2.1
assets $-135.00
misc €1
misc €-1
misc $-2.1
>>>
2011/01/01
expenses:foreign currency €100 @ $1.35
misc $2.10
assets $-135.00
misc €1 @ $1.35
misc €-1 @ $1.35
misc $-2.10
>>>=0
2015-11-22 19:37:02 +03:00
## 5. another, from ledger tests. Just one posting to price so uses @@.
hledger -f - print --explicit
<<<
2002/09/30 * 1a1a6305d06ce4b284dba0d267c23f69d70c20be
c56a21d23a6535184e7152ee138c28974f14280c 866.231000 GGGGG
a35e82730cf91569c302b313780e5895f75a62b9 $-17,783.72
>>>
2002/09/30 * 1a1a6305d06ce4b284dba0d267c23f69d70c20be
c56a21d23a6535184e7152ee138c28974f14280c 866.231000 GGGGG @@ $17,783.72
a35e82730cf91569c302b313780e5895f75a62b9 $-17,783.72
>>>=0
2015-11-22 19:37:02 +03:00
# 6. when the balance has more than two commodities, don't bother
hledger -f - print
<<<
2011/01/01
expenses:foreign currency €100
assets $-135
expenses:other £200
>>>= !0
2015-11-22 19:37:02 +03:00
# 7. another
hledger -f - balance -B
<<<
2011/01/01
expenses:foreign currency €99
assets $-130
expenses:foreign currency €1
assets $-5
>>>
$-135 assets
$135 expenses:foreign currency
--------------------
0
>>>=0
2015-11-22 19:37:02 +03:00
# 8. transaction in two commodities should balance out properly
hledger -f - balance --cost
<<<
2011/01/01 x
a 10£ @@ 16$
b
>>>
16$ a
-16$ b
--------------------
0
>>>=0
2015-11-22 19:37:02 +03:00
# 9. When commodity price is specified implicitly, transaction should
# be considered balanced out even when first amount is negative
# (that is, price for it should be determined properly, with proper sign)
hledger -f - balance
<<<
2011/01/01 x
a -10£
b 16$
>>>
-10£ a
16$ b
--------------------
16$
-10£
>>>=0
2015-11-22 19:37:02 +03:00
# 10. When commodity price is specified implicitly, transaction should
# NOT be considered balanced out when BOTH amounts are negative
hledger -f - balance
<<<
2011/01/01 x
a -10£
b -16$
>>>
>>>=1
2015-11-22 19:37:02 +03:00
# 11. Differently-priced lots of a commodity should be merged in balance report
hledger -f - balance
<<<
2011/1/1
(a) £1 @ $2
2011/1/1
(a) £1 @ $3
>>>
£2 a
--------------------
£2
>>>=0
2015-11-22 19:37:02 +03:00
# 12. this should balance
hledger -f - balance
<<<
2011/1/1
a 1h @ $10
b 1h @ $20
c $-30
>>>= 0
2015-11-22 19:37:02 +03:00
# 13. these balance because of the unit prices, and should parse successfully
hledger -f - balance --no-total
<<<
1/1
a 1X @ 2Y
a -2X @ 1Y
>>>
-1X a
>>>= 0
2015-11-22 19:37:02 +03:00
# 14.
hledger -f - balance --no-total -B
<<<
1/1
a 1X @ 2Y
a -2X @ 1Y
>>>
>>>= 0
2015-11-22 19:37:02 +03:00
# 15. likewise with total prices. Note how the primary amount's sign is used.
hledger -f - balance --no-total
<<<
1/1
a 1X @@ 1Y
a -2X @@ 1Y
>>>
-1X a
>>>= 0
2015-11-22 19:37:02 +03:00
# 16.
hledger -f - balance --no-total -B
<<<
1/1
a 1X @@ 1Y
a -2X @@ 1Y
>>>
>>>= 0
2015-11-22 19:37:02 +03:00
# 17. here, a's primary amount is 0, and its cost is 1Y; b is the assigned auto-balancing amount of -1Y (per issue 69)
hledger -f - balance --no-total -E
<<<
1/1
a 1X @@ 1Y
a 1X @@ 1Y
a -2X @@ 1Y
b
>>>
0 a
-1Y b
>>>= 0
2015-11-22 19:37:02 +03:00
# 18. the above with -B
hledger -f - balance --no-total -E -B
<<<
1/1
a 1X @@ 1Y
a 1X @@ 1Y
a -2X @@ 1Y
b
>>>
1Y a
-1Y b
>>>= 0
# # when the *cost-basis* balance has exactly two commodities, both
# # unpriced, infer an implicit conversion price for the first one in terms
# # of the second.
# hledger -f - print
# <<<
# 2011/01/01
# expenses:foreign currency €100
# assets $-135.00
# misc $3.1 @ 2 bob
# misc $-3.1 @ 2 bob
# misc £1 @@ 2 shekels
# misc £-1 @@ 2 shekels
# >>>
# 2011/01/01
# expenses:foreign currency €100 @ $1.35
# assets €-100 @ $1.35
# misc $3.1 @ 2 bob
# misc $-3.1 @ 2 bob
# misc £1 @@ 2 shekels
# misc £-1 @@ 2 shekels
#