mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-07 21:15:19 +03:00
cln: Rename balancingOpts to defbalancingopts, to be consistent with definputopts, defreportopts, etc.
This commit is contained in:
parent
e310ba574c
commit
13206d0b18
@ -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
|
||||
|
@ -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
|
||||
""
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ balanceReport rspec j = (rows, total)
|
||||
-- tests
|
||||
|
||||
Right samplejournal2 =
|
||||
journalBalanceTransactions balancingOpts
|
||||
journalBalanceTransactions defbalancingopts
|
||||
nulljournal{
|
||||
jtxns = [
|
||||
txnTieKnot Transaction{
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user