diff --git a/hledger-lib/Hledger/Data/Balancing.hs b/hledger-lib/Hledger/Data/Balancing.hs index 528d6f515..ec998ddc6 100644 --- a/hledger-lib/Hledger/Data/Balancing.hs +++ b/hledger-lib/Hledger/Data/Balancing.hs @@ -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, diff --git a/hledger/test/add.test b/hledger/test/add.test index 988992749..22409fc00 100644 --- a/hledger/test/add.test +++ b/hledger/test/add.test @@ -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 # <