Always check added transaction, even if no immediate assertion

This commit is contained in:
Michael Rees 2025-05-31 21:38:57 -05:00 committed by Simon Michael
parent db4d7d0dbe
commit 0c3e7bc395
2 changed files with 20 additions and 3 deletions

View File

@ -152,14 +152,12 @@ isTransactionBalanced bopts = null . transactionCheckBalanced bopts
-- when included in the larger journal.
transactionCheckAssertions :: BalancingOpts -> Journal -> Transaction -> Either String Transaction
transactionCheckAssertions bopts j t =
if (ignore_assertions_ bopts) || noassertions t then Right t else do
if (ignore_assertions_ bopts) then Right t else do
j' <- journalStyleAmounts j
let newtxns = sortOn tdate (jtxns j' ++ [ t ])
case journalBalanceTransactions bopts j'{jtxns = newtxns} of
Right _ -> Right t
Left e -> Left e
where
noassertions = all (isNothing . pbalanceassertion) . tpostings
-- | Balance this transaction, ensuring that its postings
-- (and its balanced virtual postings) sum to 0,

View File

@ -246,6 +246,25 @@ $ rm -f nosuch.journal; hledger -f nosuch.journal add; rm -f nosuch.journal
> /Save this transaction to the journal/
>2 //
## 18. add checks existing assertions
<
2025-05-10
x
a
10 USD == 10 USD
b
-10 USD
.
y
2025-05-01
x
a
10 USD
$ rm -f nosuch.journal; hledger -f nosuch.journal add; rm -f nosuch.journal
> //
>2 /Balance assertion failed in a/
## 18. shouldn't add decimals if there aren't any
## printf '\n\na\n1\nb\n' | hledger -f /dev/null add
# <