fix: infer amountless unbalanced virtual postings as zero

They were effectively zero already, but print always showed them with no amount, even with -x, which was unclear.
This commit is contained in:
Simon Michael 2023-05-20 17:34:11 -10:00
parent e832c344c1
commit 4a61caefd7
2 changed files with 17 additions and 4 deletions

View File

@ -241,6 +241,7 @@ transactionInferBalancingAmount styles t@Transaction{tpostings=ps}
minferredamt = case ptype p of minferredamt = case ptype p of
RegularPosting | not (hasAmount p) -> Just realsum RegularPosting | not (hasAmount p) -> Just realsum
BalancedVirtualPosting | not (hasAmount p) -> Just bvsum BalancedVirtualPosting | not (hasAmount p) -> Just bvsum
VirtualPosting | not (hasAmount p) -> Just 0
_ -> Nothing _ -> Nothing
in in
case minferredamt of case minferredamt of

View File

@ -32,18 +32,16 @@ $ hledger -f- print
2010/1/1 x 2010/1/1 x
[a] 10 [a] 10
[b] [b]
$ hledger -f- print $ hledger -f- print -x
> // > //
# 5. real and balanced virtual postings are balanced separately, and multiple blank virtuals are ok # 5. real and balanced virtual postings are balanced separately, and multiple amountless virtuals are ok
< <
2010/1/1 x 2010/1/1 x
a 1 a 1
b b
[e] 10 [e] 10
[f] [f]
(c)
(d)
$ hledger -f- balance --tree $ hledger -f- balance --tree
1 a 1 a
-1 b -1 b
@ -51,3 +49,17 @@ $ hledger -f- balance --tree
-10 f -10 f
-------------------- --------------------
0 0
# 6. Amountless unbalanced postings are always inferred as zero.
<
2023-01-01
(a)
(b)
(c)
$ hledger -f- print -x
2023-01-01
(a) 0
(b) 0
(c) 0
>=