dev: move journalCheckBalanceAssertions to JournalChecks

This commit is contained in:
Simon Michael 2024-04-26 17:11:38 -10:00
parent 0c0c088398
commit afe9e2c6f4
3 changed files with 11 additions and 8 deletions

View File

@ -20,7 +20,6 @@ module Hledger.Data.Balancing
, balanceTransactionHelper
-- * journal balancing
, journalBalanceTransactions
, journalCheckBalanceAssertions
-- * tests
, tests_Balancing
)
@ -376,11 +375,6 @@ costInferrerFor t pt = maybe id infercost inferFromAndTo
saturatedAdd a b = if maxBound - a < b then maxBound else a + b
-- | Check any balance assertions in the journal and return an error message
-- if any of them fail (or if the transaction balancing they require fails).
journalCheckBalanceAssertions :: Journal -> Maybe String
journalCheckBalanceAssertions = either Just (const Nothing) . journalBalanceTransactions defbalancingopts
-- "Transaction balancing", including: inferring missing amounts,
-- applying balance assignments, checking transaction balancedness,
-- checking balance assertions, respecting posting dates. These things

View File

@ -9,6 +9,7 @@ others can be called only via the check command.
module Hledger.Data.JournalChecks (
journalCheckAccounts,
journalCheckBalanceAssertions,
journalCheckCommodities,
journalCheckPayees,
journalCheckPairedConversionPostings,
@ -39,6 +40,8 @@ import Data.Time (Day, diffDays)
import Hledger.Utils
import Data.Ord
import Hledger.Data.Dates (showDate)
import Hledger.Data.Balancing (journalBalanceTransactions, defbalancingopts)
-- | Check that all the journal's postings are to accounts with
-- account directives, returning an error message otherwise.
@ -60,6 +63,12 @@ journalCheckAccounts j = mapM_ checkacct (journalPostings j)
where
(f,l,_mcols,ex) = makePostingAccountErrorExcerpt p
-- | Check all balance assertions in the journal and return an error message if any of them fail.
-- (Technically, this also tries to balance the journal and can return balancing failure errors;
-- ensure the journal is already balanced (with journalBalanceTransactions) to avoid this.)
journalCheckBalanceAssertions :: Journal -> Either String ()
journalCheckBalanceAssertions = fmap (const ()) . journalBalanceTransactions defbalancingopts
-- | Check that all the commodities used in this journal's postings have been declared
-- by commodity directives, returning an error message otherwise.
journalCheckCommodities :: Journal -> Either String ()

View File

@ -188,8 +188,8 @@ uiCheckBalanceAssertions _d ui@UIState{ajournal=j}
| ui^.ignore_assertions = ui
| otherwise =
case journalCheckBalanceAssertions j of
Nothing -> ui
Just err ->
Right () -> ui
Left err ->
case ui of
UIState{aScreen=ES sst} -> ui{aScreen=ES sst{_essError=err}}
_ -> pushScreen (esNew err) ui