2011-01-20 03:18:54 +03:00
|
|
|
# price-related tests
|
|
|
|
# 1. print a transaction with an explicit unit price
|
2017-01-13 18:25:44 +03:00
|
|
|
hledger -f- print --explicit
|
2011-01-20 03:18:54 +03:00
|
|
|
<<<
|
|
|
|
2011/01/01
|
|
|
|
expenses:foreign currency €100 @ $1.35
|
|
|
|
assets
|
|
|
|
>>>
|
|
|
|
2011/01/01
|
2017-06-05 07:26:18 +03:00
|
|
|
expenses:foreign currency €100 @ $1.35
|
|
|
|
assets $-135.00
|
2011-01-20 03:18:54 +03:00
|
|
|
|
2011-03-12 23:55:49 +03:00
|
|
|
>>>=0
|
|
|
|
|
2012-01-23 00:39:11 +04:00
|
|
|
# 2. -B/--cost converts to the price's commodity ("cost")
|
2017-01-13 18:25:44 +03:00
|
|
|
hledger -f- print --explicit --cost
|
2011-01-20 03:18:54 +03:00
|
|
|
<<<
|
|
|
|
2011/01/01
|
|
|
|
expenses:foreign currency €100 @ $1.35
|
|
|
|
assets
|
|
|
|
>>>
|
|
|
|
2011/01/01
|
2017-06-05 07:26:18 +03:00
|
|
|
expenses:foreign currency $135.00
|
|
|
|
assets $-135.00
|
2011-01-20 03:18:54 +03:00
|
|
|
|
2011-03-12 23:55:49 +03:00
|
|
|
>>>=0
|
|
|
|
|
2015-11-22 19:37:02 +03:00
|
|
|
# 3. print a transaction with a total price
|
2017-01-13 18:25:44 +03:00
|
|
|
hledger -f - print --explicit
|
2011-01-20 03:18:54 +03:00
|
|
|
<<<
|
|
|
|
2011/01/01
|
|
|
|
expenses:foreign currency €100 @@ $135
|
|
|
|
assets
|
|
|
|
>>>
|
|
|
|
2011/01/01
|
2017-06-05 07:26:18 +03:00
|
|
|
expenses:foreign currency €100 @@ $135
|
|
|
|
assets $-135
|
2011-01-20 03:18:54 +03:00
|
|
|
|
2011-03-12 23:55:49 +03:00
|
|
|
>>>=0
|
|
|
|
|
2015-11-22 19:37:02 +03:00
|
|
|
# 4. when the balance has exactly two commodities, both unpriced, infer an
|
2011-01-20 03:18:54 +03:00
|
|
|
# implicit conversion price for the first one in terms of the second.
|
2017-01-13 18:25:44 +03:00
|
|
|
hledger -f - print --explicit
|
2011-01-20 03:18:54 +03:00
|
|
|
<<<
|
|
|
|
2011/01/01
|
|
|
|
expenses:foreign currency €100
|
|
|
|
misc $2.1
|
|
|
|
assets $-135.00
|
|
|
|
misc €1
|
|
|
|
misc €-1
|
|
|
|
misc $-2.1
|
|
|
|
>>>
|
|
|
|
2011/01/01
|
2017-06-05 07:26:18 +03:00
|
|
|
expenses:foreign currency €100 @ $1.35
|
|
|
|
misc $2.10
|
|
|
|
assets $-135.00
|
|
|
|
misc €1 @ $1.35
|
|
|
|
misc €-1 @ $1.35
|
|
|
|
misc $-2.10
|
2011-01-20 03:18:54 +03:00
|
|
|
|
2011-03-12 23:55:49 +03:00
|
|
|
>>>=0
|
|
|
|
|
2015-11-22 19:37:02 +03:00
|
|
|
## 5. another, from ledger tests. Just one posting to price so uses @@.
|
2017-01-13 18:25:44 +03:00
|
|
|
hledger -f - print --explicit
|
2011-01-20 03:18:54 +03:00
|
|
|
<<<
|
|
|
|
2002/09/30 * 1a1a6305d06ce4b284dba0d267c23f69d70c20be
|
|
|
|
c56a21d23a6535184e7152ee138c28974f14280c 866.231000 GGGGG
|
|
|
|
a35e82730cf91569c302b313780e5895f75a62b9 $-17,783.72
|
|
|
|
>>>
|
|
|
|
2002/09/30 * 1a1a6305d06ce4b284dba0d267c23f69d70c20be
|
2017-06-05 07:26:18 +03:00
|
|
|
c56a21d23a6535184e7152ee138c28974f14280c 866.231000 GGGGG @@ $17,783.72
|
|
|
|
a35e82730cf91569c302b313780e5895f75a62b9 $-17,783.72
|
2011-01-20 03:18:54 +03:00
|
|
|
|
2011-03-12 23:55:49 +03:00
|
|
|
>>>=0
|
|
|
|
|
2015-11-22 19:37:02 +03:00
|
|
|
# 6. when the balance has more than two commodities, don't bother
|
2015-07-12 21:54:08 +03:00
|
|
|
hledger -f - print
|
2011-01-20 03:18:54 +03:00
|
|
|
<<<
|
|
|
|
2011/01/01
|
2017-06-05 07:26:18 +03:00
|
|
|
expenses:foreign currency €100
|
|
|
|
assets $-135
|
|
|
|
expenses:other £200
|
2011-01-20 03:18:54 +03:00
|
|
|
>>>= !0
|
2012-11-12 20:31:43 +04:00
|
|
|
|
2015-11-22 19:37:02 +03:00
|
|
|
# 7. another
|
2015-07-12 21:54:08 +03:00
|
|
|
hledger -f - balance -B
|
2011-01-20 03:18:54 +03:00
|
|
|
<<<
|
|
|
|
2011/01/01
|
|
|
|
expenses:foreign currency €99
|
|
|
|
assets $-130
|
|
|
|
expenses:foreign currency €1
|
|
|
|
assets $-5
|
|
|
|
>>>
|
|
|
|
$-135 assets
|
|
|
|
$135 expenses:foreign currency
|
|
|
|
--------------------
|
2011-04-22 17:50:05 +04:00
|
|
|
0
|
2011-03-12 23:55:49 +03:00
|
|
|
>>>=0
|
2012-11-12 20:31:43 +04:00
|
|
|
|
2015-11-22 19:37:02 +03:00
|
|
|
# 8. transaction in two commodities should balance out properly
|
2015-07-12 21:54:08 +03:00
|
|
|
hledger -f - balance --cost
|
2011-04-20 00:15:11 +04:00
|
|
|
<<<
|
|
|
|
2011/01/01 x
|
|
|
|
a 10£ @@ 16$
|
|
|
|
b
|
|
|
|
>>>
|
|
|
|
16$ a
|
|
|
|
-16$ b
|
|
|
|
--------------------
|
2011-04-22 17:50:05 +04:00
|
|
|
0
|
2011-04-20 00:15:11 +04:00
|
|
|
>>>=0
|
2012-11-12 20:31:43 +04:00
|
|
|
|
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)
|
2015-07-12 21:54:08 +03:00
|
|
|
hledger -f - balance
|
2011-04-25 02:10:30 +04:00
|
|
|
<<<
|
|
|
|
2011/01/01 x
|
|
|
|
a -10£
|
|
|
|
b 16$
|
|
|
|
>>>
|
|
|
|
-10£ a
|
|
|
|
16$ b
|
|
|
|
--------------------
|
|
|
|
16$
|
|
|
|
-10£
|
|
|
|
>>>=0
|
2012-11-12 20:31:43 +04:00
|
|
|
|
2015-11-22 19:37:02 +03:00
|
|
|
# 10. When commodity price is specified implicitly, transaction should
|
2011-04-25 22:37:59 +04:00
|
|
|
# NOT be considered balanced out when BOTH amounts are negative
|
2015-07-12 21:54:08 +03:00
|
|
|
hledger -f - balance
|
2011-04-25 22:37:59 +04:00
|
|
|
<<<
|
|
|
|
2011/01/01 x
|
|
|
|
a -10£
|
|
|
|
b -16$
|
|
|
|
>>>
|
|
|
|
>>>=1
|
2012-01-01 04:39:13 +04:00
|
|
|
|
2015-11-22 19:37:02 +03:00
|
|
|
# 11. Differently-priced lots of a commodity should be merged in balance report
|
2015-07-12 21:54:08 +03:00
|
|
|
hledger -f - balance
|
2012-01-01 04:39:13 +04:00
|
|
|
<<<
|
|
|
|
2011/1/1
|
|
|
|
(a) £1 @ $2
|
|
|
|
|
|
|
|
2011/1/1
|
|
|
|
(a) £1 @ $3
|
|
|
|
>>>
|
|
|
|
£2 a
|
|
|
|
--------------------
|
|
|
|
£2
|
|
|
|
>>>=0
|
2012-01-23 00:39:11 +04:00
|
|
|
|
2015-11-22 19:37:02 +03:00
|
|
|
# 12. this should balance
|
2015-07-12 21:54:08 +03:00
|
|
|
hledger -f - balance
|
2012-01-23 00:39:11 +04:00
|
|
|
<<<
|
|
|
|
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
|
2015-07-12 21:54:08 +03:00
|
|
|
hledger -f - balance --no-total
|
2012-11-12 20:31:43 +04:00
|
|
|
<<<
|
|
|
|
1/1
|
|
|
|
a 1X @ 2Y
|
|
|
|
a -2X @ 1Y
|
|
|
|
>>>
|
|
|
|
-1X a
|
|
|
|
>>>= 0
|
|
|
|
|
2015-11-22 19:37:02 +03:00
|
|
|
# 14.
|
2015-07-12 21:54:08 +03:00
|
|
|
hledger -f - balance --no-total -B
|
2012-11-12 20:31:43 +04:00
|
|
|
<<<
|
|
|
|
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.
|
2015-07-12 21:54:08 +03:00
|
|
|
hledger -f - balance --no-total
|
2012-11-12 20:31:43 +04:00
|
|
|
<<<
|
|
|
|
1/1
|
|
|
|
a 1X @@ 1Y
|
|
|
|
a -2X @@ 1Y
|
|
|
|
>>>
|
|
|
|
-1X a
|
|
|
|
>>>= 0
|
|
|
|
|
2015-11-22 19:37:02 +03:00
|
|
|
# 16.
|
2015-07-12 21:54:08 +03:00
|
|
|
hledger -f - balance --no-total -B
|
2012-11-12 20:31:43 +04:00
|
|
|
<<<
|
|
|
|
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)
|
2015-07-12 21:54:08 +03:00
|
|
|
hledger -f - balance --no-total -E
|
2012-11-12 20:31:43 +04:00
|
|
|
<<<
|
|
|
|
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
|
2015-07-12 21:54:08 +03:00
|
|
|
hledger -f - balance --no-total -E -B
|
2012-11-12 20:31:43 +04:00
|
|
|
<<<
|
|
|
|
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.
|
2015-07-12 21:54:08 +03:00
|
|
|
# hledger -f - print
|
2012-11-12 20:31:43 +04:00
|
|
|
# <<<
|
|
|
|
# 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
|
|
|
|
#
|