diff --git a/hledger-lib/Hledger/Data/JournalChecks.hs b/hledger-lib/Hledger/Data/JournalChecks.hs index dabfb2778..dba78ce7a 100644 --- a/hledger-lib/Hledger/Data/JournalChecks.hs +++ b/hledger-lib/Hledger/Data/JournalChecks.hs @@ -33,7 +33,7 @@ import Hledger.Data.JournalChecks.Ordereddates import Hledger.Data.JournalChecks.Uniqueleafnames import Hledger.Data.Posting (isVirtual, postingDate, transactionAllTags) import Hledger.Data.Types -import Hledger.Data.Amount (amountIsZero, amountsRaw, missingamt) +import Hledger.Data.Amount (amountIsZero, amountsRaw, missingamt, amounts) import Hledger.Data.Transaction (transactionPayee, showTransactionLineFirstPart, partitionAndCheckConversionPostings) import Data.Time (Day, diffDays) import Hledger.Utils @@ -239,6 +239,11 @@ findRecentAssertionError today ps = do let lag = diffDays (postingDate firsterrorp) latestassertdate let acct = paccount firsterrorp let (f,l,_mcols,ex) = makePostingAccountErrorExcerpt firsterrorp + let comm = + case map acommodity $ amounts $ pamount firsterrorp of + [] -> "" + (t:_) | T.length t == 1 -> t + (t:_) -> t <> " " Just $ chomp $ printf (unlines [ "%s:%d:", @@ -250,7 +255,7 @@ findRecentAssertionError today ps = do "", "Consider adding a more recent balance assertion for this account. Eg:", "", - "%s *\n %s $0 = $0 ; (adjust asserted amount)" + "%s\n %s %s0 = %s0 ; (adjust asserted amount)" ]) f l @@ -261,6 +266,8 @@ findRecentAssertionError today ps = do (showDate latestassertdate) (show today) acct + comm + comm -- -- | Print the last balance assertion date & status of all accounts with balance assertions. -- printAccountLastAssertions :: Day -> [BalanceAssertionInfo] -> IO () diff --git a/hledger/test/errors/recentassertions.j b/hledger/test/errors/recentassertions.j index c1370e626..e4865cabf 100755 --- a/hledger/test/errors/recentassertions.j +++ b/hledger/test/errors/recentassertions.j @@ -1,5 +1,4 @@ #!/usr/bin/env -S hledger check recentassertions -f -# Postings more than 7 days after latest balance assertion. 2022-01-01 * a 0 = 0 @@ -7,6 +6,7 @@ 2022-01-08 good a 0 +# More than 7 days after latest balance assertion, fails this check. 2022-01-09 bad1 a 0 diff --git a/hledger/test/errors/recentassertions.test b/hledger/test/errors/recentassertions.test index 1723277a1..b837141b8 100644 --- a/hledger/test/errors/recentassertions.test +++ b/hledger/test/errors/recentassertions.test @@ -1,3 +1,4 @@ +# 1. The first posting more than 7 days after latest balance assertion causes this check to fail. $ hledger check recentassertions -f recentassertions.j >2 /Error: .*recentassertions.j:11: | 2022-01-09 bad1