mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-18 17:57:11 +03:00
dev: move journalCheckBalanceAssertions to JournalChecks
This commit is contained in:
parent
0c0c088398
commit
afe9e2c6f4
@ -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
|
||||
|
@ -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 ()
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user