Safe Haskell | None |
---|---|
Language | Haskell2010 |
Functions for ensuring transactions and journals are balanced.
Synopsis
- data BalancingOpts = BalancingOpts {}
- class HasBalancingOpts c where
- defbalancingopts :: BalancingOpts
- isTransactionBalanced :: BalancingOpts -> Transaction -> Bool
- balanceTransaction :: BalancingOpts -> Transaction -> Either String Transaction
- balanceTransactionHelper :: BalancingOpts -> Transaction -> Either String (Transaction, [(AccountName, MixedAmount)])
- annotateErrorWithTransaction :: Transaction -> String -> String
- journalBalanceTransactions :: BalancingOpts -> Journal -> Either String Journal
- journalCheckBalanceAssertions :: Journal -> Maybe String
- tests_Balancing :: TestTree
BalancingOpts
data BalancingOpts Source #
BalancingOpts | |
|
Instances
Show BalancingOpts Source # | |
Defined in Hledger.Data.Balancing showsPrec :: Int -> BalancingOpts -> ShowS # show :: BalancingOpts -> String # showList :: [BalancingOpts] -> ShowS # | |
HasBalancingOpts BalancingOpts Source # | |
class HasBalancingOpts c where Source #
balancingOpts :: Lens' c BalancingOpts Source #
commodity_styles :: Lens' c (Maybe (Map CommoditySymbol AmountStyle)) Source #
ignore_assertions :: Lens' c Bool Source #
Instances
transaction balancing
isTransactionBalanced :: BalancingOpts -> Transaction -> Bool Source #
Legacy form of transactionCheckBalanced.
balanceTransaction :: BalancingOpts -> Transaction -> Either String Transaction Source #
Balance this transaction, ensuring that its postings (and its balanced virtual postings) sum to 0, by inferring a missing amount or conversion price(s) if needed. Or if balancing is not possible, because the amounts don't sum to 0 or because there's more than one missing amount, return an error message.
Transactions with balance assignments can have more than one missing amount; to balance those you should use the more powerful journalBalanceTransactions.
The "sum to 0" test is done using commodity display precisions, if provided, so that the result agrees with the numbers users can see.
balanceTransactionHelper :: BalancingOpts -> Transaction -> Either String (Transaction, [(AccountName, MixedAmount)]) Source #
Helper used by balanceTransaction and balanceTransactionWithBalanceAssignmentAndCheckAssertionsB; use one of those instead. It also returns a list of accounts and amounts that were inferred.
journal balancing
journalBalanceTransactions :: BalancingOpts -> Journal -> Either String Journal Source #
Infer any missing amounts (to satisfy balance assignments and to balance transactions) and check that all transactions balance and (optional) all balance assertions pass. Or return an error message (just the first error encountered).
Assumes journalInferCommodityStyles has been called, since those affect transaction balancing.
This does multiple things at once because amount inferring, balance assignments, balance assertions and posting dates are interdependent.
journalCheckBalanceAssertions :: Journal -> Maybe String Source #
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).