From 4a61caefd760e0eb74c53f1daa421326e43fd7f3 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 20 May 2023 17:34:11 -1000 Subject: [PATCH] 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. --- hledger-lib/Hledger/Data/Balancing.hs | 1 + hledger/test/journal/virtual-postings.test | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/hledger-lib/Hledger/Data/Balancing.hs b/hledger-lib/Hledger/Data/Balancing.hs index 11bf47e62..ce05a2cb5 100644 --- a/hledger-lib/Hledger/Data/Balancing.hs +++ b/hledger-lib/Hledger/Data/Balancing.hs @@ -241,6 +241,7 @@ transactionInferBalancingAmount styles t@Transaction{tpostings=ps} minferredamt = case ptype p of RegularPosting | not (hasAmount p) -> Just realsum BalancedVirtualPosting | not (hasAmount p) -> Just bvsum + VirtualPosting | not (hasAmount p) -> Just 0 _ -> Nothing in case minferredamt of diff --git a/hledger/test/journal/virtual-postings.test b/hledger/test/journal/virtual-postings.test index 0a6b9f805..1104bec47 100644 --- a/hledger/test/journal/virtual-postings.test +++ b/hledger/test/journal/virtual-postings.test @@ -32,18 +32,16 @@ $ hledger -f- print 2010/1/1 x [a] 10 [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 a 1 b [e] 10 [f] - (c) - (d) $ hledger -f- balance --tree 1 a -1 b @@ -51,3 +49,17 @@ $ hledger -f- balance --tree -10 f -------------------- 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 + +>=