dev: move journalCheckBalanceAssertions to JournalChecks
This commit is contained in:
parent
0c0c088398
commit
afe9e2c6f4
@ -20,7 +20,6 @@ module Hledger.Data.Balancing
|
|||||||
, balanceTransactionHelper
|
, balanceTransactionHelper
|
||||||
-- * journal balancing
|
-- * journal balancing
|
||||||
, journalBalanceTransactions
|
, journalBalanceTransactions
|
||||||
, journalCheckBalanceAssertions
|
|
||||||
-- * tests
|
-- * tests
|
||||||
, tests_Balancing
|
, 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
|
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,
|
-- "Transaction balancing", including: inferring missing amounts,
|
||||||
-- applying balance assignments, checking transaction balancedness,
|
-- applying balance assignments, checking transaction balancedness,
|
||||||
-- checking balance assertions, respecting posting dates. These things
|
-- 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 (
|
module Hledger.Data.JournalChecks (
|
||||||
journalCheckAccounts,
|
journalCheckAccounts,
|
||||||
|
journalCheckBalanceAssertions,
|
||||||
journalCheckCommodities,
|
journalCheckCommodities,
|
||||||
journalCheckPayees,
|
journalCheckPayees,
|
||||||
journalCheckPairedConversionPostings,
|
journalCheckPairedConversionPostings,
|
||||||
@ -39,6 +40,8 @@ import Data.Time (Day, diffDays)
|
|||||||
import Hledger.Utils
|
import Hledger.Utils
|
||||||
import Data.Ord
|
import Data.Ord
|
||||||
import Hledger.Data.Dates (showDate)
|
import Hledger.Data.Dates (showDate)
|
||||||
|
import Hledger.Data.Balancing (journalBalanceTransactions, defbalancingopts)
|
||||||
|
|
||||||
|
|
||||||
-- | Check that all the journal's postings are to accounts with
|
-- | Check that all the journal's postings are to accounts with
|
||||||
-- account directives, returning an error message otherwise.
|
-- account directives, returning an error message otherwise.
|
||||||
@ -60,6 +63,12 @@ journalCheckAccounts j = mapM_ checkacct (journalPostings j)
|
|||||||
where
|
where
|
||||||
(f,l,_mcols,ex) = makePostingAccountErrorExcerpt p
|
(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
|
-- | Check that all the commodities used in this journal's postings have been declared
|
||||||
-- by commodity directives, returning an error message otherwise.
|
-- by commodity directives, returning an error message otherwise.
|
||||||
journalCheckCommodities :: Journal -> Either String ()
|
journalCheckCommodities :: Journal -> Either String ()
|
||||||
|
|||||||
@ -188,8 +188,8 @@ uiCheckBalanceAssertions _d ui@UIState{ajournal=j}
|
|||||||
| ui^.ignore_assertions = ui
|
| ui^.ignore_assertions = ui
|
||||||
| otherwise =
|
| otherwise =
|
||||||
case journalCheckBalanceAssertions j of
|
case journalCheckBalanceAssertions j of
|
||||||
Nothing -> ui
|
Right () -> ui
|
||||||
Just err ->
|
Left err ->
|
||||||
case ui of
|
case ui of
|
||||||
UIState{aScreen=ES sst} -> ui{aScreen=ES sst{_essError=err}}
|
UIState{aScreen=ES sst} -> ui{aScreen=ES sst{_essError=err}}
|
||||||
_ -> pushScreen (esNew err) ui
|
_ -> pushScreen (esNew err) ui
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user