| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Hledger.Data.Balancing
Description
Functions for ensuring transactions and journals are balanced.
Synopsis
- data BalancingOpts = BalancingOpts {}
- class HasBalancingOpts c where
- defbalancingopts :: BalancingOpts
- isTransactionBalanced :: BalancingOpts -> Transaction -> Bool
- balanceSingleTransaction :: BalancingOpts -> Transaction -> Either String Transaction
- balanceTransactionHelper :: BalancingOpts -> Transaction -> Either String (Transaction, [(AccountName, MixedAmount)])
- transactionCheckAssertions :: BalancingOpts -> Journal -> Transaction -> Either String Transaction
- journalBalanceTransactions :: BalancingOpts -> Journal -> Either String Journal
- tests_Balancing :: TestTree
BalancingOpts
data BalancingOpts Source #
Constructors
| BalancingOpts | |
Fields
| |
Instances
class HasBalancingOpts c where Source #
Minimal complete definition
Methods
balancingOpts :: Lens' c BalancingOpts Source #
commodity_styles :: Lens' c (Maybe (Map CommoditySymbol AmountStyle)) Source #
ignore_assertions :: Lens' c Bool Source #
infer_balancing_costs :: Lens' c Bool Source #
txn_balancing :: Lens' c TransactionBalancingPrecision Source #
Instances
transaction balancing
isTransactionBalanced :: BalancingOpts -> Transaction -> Bool Source #
Legacy form of transactionCheckBalanced.
balanceSingleTransaction :: BalancingOpts -> Transaction -> Either String Transaction Source #
Balance this isolated 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.
Note this is not as accurate as balanceTransactionInJournal,
which considers the whole journal when calculating balance assignments and balance assertions.
balanceTransactionHelper :: BalancingOpts -> Transaction -> Either String (Transaction, [(AccountName, MixedAmount)]) Source #
Helper used by balanceSingleTransaction and balanceTransactionWithBalanceAssignmentAndCheckAssertionsB; use one of those instead. It also returns a list of accounts and amounts that were inferred.
assertion validation
transactionCheckAssertions :: BalancingOpts -> Journal -> Transaction -> Either String Transaction Source #
Verify that any assertions in this transaction hold when included in the larger journal.
journal balancing
journalBalanceTransactions :: BalancingOpts -> Journal -> Either String Journal Source #
Infer any missing amounts and/or conversion costs (as needed to balance transactions and satisfy balance assignments); and check that all transactions are balanced; and (optional) check that all balance assertions pass. Or, return an error message (just the first error encountered).
Assumes journalStyleAmounts has been called, since amount styles affect transaction balancing.
This does multiple things at once because amount inferring, balance assignments, balance assertions and posting dates are interdependent.