imp:check:recentassertions: improve the error message's suggestion
The suggested sample balance assertion now uses the same commodity symbol as in the failing posting (the first, if there are more than one). Also the cleared mark has been removed.
This commit is contained in:
parent
002773f650
commit
ed456a3f8c
@ -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 ()
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user