From 13206d0b1885a56cac3196b861b5864a4e471e4d Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Mon, 23 Aug 2021 23:15:04 +1000 Subject: [PATCH] cln: Rename balancingOpts to defbalancingopts, to be consistent with definputopts, defreportopts, etc. --- hledger-lib/Hledger/Data/Journal.hs | 14 ++++----- hledger-lib/Hledger/Data/Transaction.hs | 32 ++++++++++---------- hledger-lib/Hledger/Read/Common.hs | 2 +- hledger-lib/Hledger/Read/InputOptions.hs | 4 +-- hledger-lib/Hledger/Reports/BalanceReport.hs | 2 +- hledger-web/Hledger/Web/Widget/AddForm.hs | 2 +- hledger/Hledger/Cli/Commands/Add.hs | 4 +-- hledger/Hledger/Cli/Commands/Diff.hs | 2 +- hledger/Hledger/Cli/Commands/Import.hs | 2 +- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index 92c5c67c5..788588b9e 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -723,7 +723,7 @@ journalModifyTransactions d j = -- | 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 balancingOpts +journalCheckBalanceAssertions = either Just (const Nothing) . journalBalanceTransactions defbalancingopts -- "Transaction balancing", including: inferring missing amounts, -- applying balance assignments, checking transaction balancedness, @@ -886,7 +886,7 @@ balanceTransactionAndCheckAssertionsB (Right t@Transaction{tpostings=ps}) = do ps' <- mapM (addOrAssignAmountAndCheckAssertionB . postingStripPrices) ps -- infer any remaining missing amounts, and make sure the transaction is now fully balanced styles <- R.reader bsStyles - case balanceTransactionHelper balancingOpts{commodity_styles_=styles} t{tpostings=ps'} of + case balanceTransactionHelper defbalancingopts{commodity_styles_=styles} t{tpostings=ps'} of Left err -> throwError err Right (t', inferredacctsandamts) -> do -- for each amount just inferred, update the running balance @@ -1408,7 +1408,7 @@ journalApplyAliases aliases j = -- liabilities:debts $1 -- assets:bank:checking -- -Right samplejournal = journalBalanceTransactions balancingOpts $ +Right samplejournal = journalBalanceTransactions defbalancingopts $ nulljournal {jtxns = [ txnTieKnot $ Transaction { @@ -1551,7 +1551,7 @@ tests_Journal = tests "Journal" [ ,tests "journalBalanceTransactions" [ test "balance-assignment" $ do - let ej = journalBalanceTransactions balancingOpts $ + let ej = journalBalanceTransactions defbalancingopts $ --2019/01/01 -- (a) = 1 nulljournal{ jtxns = [ @@ -1562,7 +1562,7 @@ tests_Journal = tests "Journal" [ (jtxns j & head & tpostings & head & pamount & amountsRaw) @?= [num 1] ,test "same-day-1" $ do - assertRight $ journalBalanceTransactions balancingOpts $ + assertRight $ journalBalanceTransactions defbalancingopts $ --2019/01/01 -- (a) = 1 --2019/01/01 @@ -1573,7 +1573,7 @@ tests_Journal = tests "Journal" [ ]} ,test "same-day-2" $ do - assertRight $ journalBalanceTransactions balancingOpts $ + assertRight $ journalBalanceTransactions defbalancingopts $ --2019/01/01 -- (a) 2 = 2 --2019/01/01 @@ -1591,7 +1591,7 @@ tests_Journal = tests "Journal" [ ]} ,test "out-of-order" $ do - assertRight $ journalBalanceTransactions balancingOpts $ + assertRight $ journalBalanceTransactions defbalancingopts $ --2019/1/2 -- (a) 1 = 2 --2019/1/1 diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index a1d09654e..0dc9981eb 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -30,7 +30,7 @@ module Hledger.Data.Transaction ( balancedVirtualPostings, transactionsPostings, BalancingOpts(..), - balancingOpts, + defbalancingopts, isTransactionBalanced, balanceTransaction, balanceTransactionHelper, @@ -360,8 +360,8 @@ data BalancingOpts = BalancingOpts , commodity_styles_ :: Maybe (M.Map CommoditySymbol AmountStyle) -- ^ commodity display styles } deriving (Show) -balancingOpts :: BalancingOpts -balancingOpts = BalancingOpts +defbalancingopts :: BalancingOpts +defbalancingopts = BalancingOpts { ignore_assertions_ = False , infer_prices_ = True , commodity_styles_ = Nothing @@ -854,7 +854,7 @@ tests_Transaction = , tests "balanceTransaction" [ test "detect unbalanced entry, sign error" $ assertLeft - (balanceTransaction balancingOpts + (balanceTransaction defbalancingopts (Transaction 0 "" @@ -869,7 +869,7 @@ tests_Transaction = [posting {paccount = "a", pamount = mixedAmount (usd 1)}, posting {paccount = "b", pamount = mixedAmount (usd 1)}])) ,test "detect unbalanced entry, multiple missing amounts" $ assertLeft $ - balanceTransaction balancingOpts + balanceTransaction defbalancingopts (Transaction 0 "" @@ -886,7 +886,7 @@ tests_Transaction = ]) ,test "one missing amount is inferred" $ (pamount . last . tpostings <$> - balanceTransaction balancingOpts + balanceTransaction defbalancingopts (Transaction 0 "" @@ -902,7 +902,7 @@ tests_Transaction = Right (mixedAmount $ usd (-1)) ,test "conversion price is inferred" $ (pamount . head . tpostings <$> - balanceTransaction balancingOpts + balanceTransaction defbalancingopts (Transaction 0 "" @@ -920,7 +920,7 @@ tests_Transaction = Right (mixedAmount $ usd 1.35 @@ eur 1) ,test "balanceTransaction balances based on cost if there are unit prices" $ assertRight $ - balanceTransaction balancingOpts + balanceTransaction defbalancingopts (Transaction 0 "" @@ -937,7 +937,7 @@ tests_Transaction = ]) ,test "balanceTransaction balances based on cost if there are total prices" $ assertRight $ - balanceTransaction balancingOpts + balanceTransaction defbalancingopts (Transaction 0 "" @@ -956,7 +956,7 @@ tests_Transaction = , tests "isTransactionBalanced" [ test "detect balanced" $ assertBool "" $ - isTransactionBalanced balancingOpts $ + isTransactionBalanced defbalancingopts $ Transaction 0 "" @@ -974,7 +974,7 @@ tests_Transaction = ,test "detect unbalanced" $ assertBool "" $ not $ - isTransactionBalanced balancingOpts $ + isTransactionBalanced defbalancingopts $ Transaction 0 "" @@ -992,7 +992,7 @@ tests_Transaction = ,test "detect unbalanced, one posting" $ assertBool "" $ not $ - isTransactionBalanced balancingOpts $ + isTransactionBalanced defbalancingopts $ Transaction 0 "" @@ -1007,7 +1007,7 @@ tests_Transaction = [posting {paccount = "b", pamount = mixedAmount (usd 1.00)}] ,test "one zero posting is considered balanced for now" $ assertBool "" $ - isTransactionBalanced balancingOpts $ + isTransactionBalanced defbalancingopts $ Transaction 0 "" @@ -1022,7 +1022,7 @@ tests_Transaction = [posting {paccount = "b", pamount = mixedAmount (usd 0)}] ,test "virtual postings don't need to balance" $ assertBool "" $ - isTransactionBalanced balancingOpts $ + isTransactionBalanced defbalancingopts $ Transaction 0 "" @@ -1041,7 +1041,7 @@ tests_Transaction = ,test "balanced virtual postings need to balance among themselves" $ assertBool "" $ not $ - isTransactionBalanced balancingOpts $ + isTransactionBalanced defbalancingopts $ Transaction 0 "" @@ -1059,7 +1059,7 @@ tests_Transaction = ] ,test "balanced virtual postings need to balance among themselves (2)" $ assertBool "" $ - isTransactionBalanced balancingOpts $ + isTransactionBalanced defbalancingopts $ Transaction 0 "" diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 2ae328639..edc0779ed 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -253,7 +253,7 @@ rawOptsToInputOpts rawopts = do ,forecast_ = forecastPeriodFromRawOpts d rawopts ,reportspan_ = DateSpan (queryStartDate False datequery) (queryEndDate False datequery) ,auto_ = boolopt "auto" rawopts - ,balancingopts_ = balancingOpts{ + ,balancingopts_ = defbalancingopts{ ignore_assertions_ = boolopt "ignore-assertions" rawopts , infer_prices_ = not noinferprice , commodity_styles_ = rawOptsToCommodityStylesOpts rawopts diff --git a/hledger-lib/Hledger/Read/InputOptions.hs b/hledger-lib/Hledger/Read/InputOptions.hs index ed515bb33..97398189f 100644 --- a/hledger-lib/Hledger/Read/InputOptions.hs +++ b/hledger-lib/Hledger/Read/InputOptions.hs @@ -16,7 +16,7 @@ import Control.Applicative ((<|>)) import Data.Time (Day, addDays) import Hledger.Data.Types -import Hledger.Data.Transaction (BalancingOpts(..), balancingOpts) +import Hledger.Data.Transaction (BalancingOpts(..), defbalancingopts) import Hledger.Data.Journal (journalEndDate) import Hledger.Data.Dates (nulldatespan) import Hledger.Utils @@ -50,7 +50,7 @@ definputopts = InputOpts , forecast_ = Nothing , reportspan_ = nulldatespan , auto_ = False - , balancingopts_ = balancingOpts + , balancingopts_ = defbalancingopts , strict_ = False } diff --git a/hledger-lib/Hledger/Reports/BalanceReport.hs b/hledger-lib/Hledger/Reports/BalanceReport.hs index 9a0419053..b80c0ae5e 100644 --- a/hledger-lib/Hledger/Reports/BalanceReport.hs +++ b/hledger-lib/Hledger/Reports/BalanceReport.hs @@ -78,7 +78,7 @@ balanceReport rspec j = (rows, total) -- tests Right samplejournal2 = - journalBalanceTransactions balancingOpts + journalBalanceTransactions defbalancingopts nulljournal{ jtxns = [ txnTieKnot Transaction{ diff --git a/hledger-web/Hledger/Web/Widget/AddForm.hs b/hledger-web/Hledger/Web/Widget/AddForm.hs index 39f7a69be..f024dec85 100644 --- a/hledger-web/Hledger/Web/Widget/AddForm.hs +++ b/hledger-web/Hledger/Web/Widget/AddForm.hs @@ -116,7 +116,7 @@ validateTransaction :: -> FormResult Transaction validateTransaction dateRes descRes postingsRes = case makeTransaction <$> dateRes <*> descRes <*> postingsRes of - FormSuccess txn -> case balanceTransaction balancingOpts txn of + FormSuccess txn -> case balanceTransaction defbalancingopts txn of Left e -> FormFailure [T.pack e] Right txn' -> FormSuccess txn' x -> x diff --git a/hledger/Hledger/Cli/Commands/Add.hs b/hledger/Hledger/Cli/Commands/Add.hs index e7baba8aa..8963b4016 100644 --- a/hledger/Hledger/Cli/Commands/Add.hs +++ b/hledger/Hledger/Cli/Commands/Add.hs @@ -203,7 +203,7 @@ confirmedTransactionWizard prevInput es@EntryState{..} stack@(currentStage : _) ,tcomment=txnCmnt ,tpostings=esPostings } - case balanceTransaction balancingOpts t of -- imprecise balancing (?) + case balanceTransaction defbalancingopts t of -- imprecise balancing (?) Right t' -> confirmedTransactionWizard prevInput es (EndStage t' : stack) Left err -> do @@ -292,7 +292,7 @@ descriptionAndCommentWizard PrevInput{..} EntryState{..} = do return $ Just (desc, comment) postingsBalanced :: [Posting] -> Bool -postingsBalanced ps = isRight $ balanceTransaction balancingOpts nulltransaction{tpostings=ps} +postingsBalanced ps = isRight $ balanceTransaction defbalancingopts nulltransaction{tpostings=ps} accountWizard PrevInput{..} EntryState{..} = do let pnum = length esPostings + 1 diff --git a/hledger/Hledger/Cli/Commands/Diff.hs b/hledger/Hledger/Cli/Commands/Diff.hs index 155cee359..a66db04dd 100644 --- a/hledger/Hledger/Cli/Commands/Diff.hs +++ b/hledger/Hledger/Cli/Commands/Diff.hs @@ -84,7 +84,7 @@ matching ppl ppr = do readJournalFile' :: FilePath -> IO Journal readJournalFile' fn = - readJournalFile definputopts{balancingopts_=balancingOpts{ignore_assertions_=True}} fn >>= either error' return -- PARTIAL: + readJournalFile definputopts{balancingopts_=defbalancingopts{ignore_assertions_=True}} fn >>= either error' return -- PARTIAL: matchingPostings :: AccountName -> Journal -> [PostingWithPath] matchingPostings acct j = filter ((== acct) . paccount . ppposting) $ allPostingsWithPath j diff --git a/hledger/Hledger/Cli/Commands/Import.hs b/hledger/Hledger/Cli/Commands/Import.hs index 5fa31cc84..87efec213 100755 --- a/hledger/Hledger/Cli/Commands/Import.hs +++ b/hledger/Hledger/Cli/Commands/Import.hs @@ -42,7 +42,7 @@ importcmd opts@CliOpts{rawopts_=rawopts,inputopts_=iopts} j = do Nothing -> Just inferredStyles Just inputStyles -> Just $ inputStyles <> inferredStyles - iopts' = iopts{new_=True, new_save_=not dryrun, balancingopts_=balancingOpts{commodity_styles_= combinedStyles}} + iopts' = iopts{new_=True, new_save_=not dryrun, balancingopts_=defbalancingopts{commodity_styles_= combinedStyles}} case inputfiles of [] -> error' "please provide one or more input files as arguments" -- PARTIAL: fs -> do