;lib: Transaction: as Map -> as M
This commit is contained in:
parent
e83cbacbf6
commit
de0a6b1e62
@ -60,7 +60,7 @@ import Data.Text (Text)
|
|||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import Data.Time.Calendar
|
import Data.Time.Calendar
|
||||||
import Text.Printf
|
import Text.Printf
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as M
|
||||||
|
|
||||||
import Hledger.Utils
|
import Hledger.Utils
|
||||||
import Hledger.Data.Types
|
import Hledger.Data.Types
|
||||||
@ -356,7 +356,7 @@ transactionPostingBalances t = (sumPostings $ realPostings t
|
|||||||
-- and summing the real postings, and summing the balanced virtual postings;
|
-- and summing the real postings, and summing the balanced virtual postings;
|
||||||
-- and applying the given display styles if any (maybe affecting decimal places);
|
-- and applying the given display styles if any (maybe affecting decimal places);
|
||||||
-- do both totals appear to be zero when rendered ?
|
-- do both totals appear to be zero when rendered ?
|
||||||
isTransactionBalanced :: Maybe (Map.Map CommoditySymbol AmountStyle) -> Transaction -> Bool
|
isTransactionBalanced :: Maybe (M.Map CommoditySymbol AmountStyle) -> Transaction -> Bool
|
||||||
isTransactionBalanced styles t =
|
isTransactionBalanced styles t =
|
||||||
-- isReallyZeroMixedAmountCost rsum && isReallyZeroMixedAmountCost bvsum
|
-- isReallyZeroMixedAmountCost rsum && isReallyZeroMixedAmountCost bvsum
|
||||||
isZeroMixedAmount rsum' && isZeroMixedAmount bvsum'
|
isZeroMixedAmount rsum' && isZeroMixedAmount bvsum'
|
||||||
@ -380,7 +380,7 @@ isTransactionBalanced styles t =
|
|||||||
-- if provided, so that the result agrees with the numbers users can see.
|
-- if provided, so that the result agrees with the numbers users can see.
|
||||||
--
|
--
|
||||||
balanceTransaction ::
|
balanceTransaction ::
|
||||||
Maybe (Map.Map CommoditySymbol AmountStyle) -- ^ commodity display styles
|
Maybe (M.Map CommoditySymbol AmountStyle) -- ^ commodity display styles
|
||||||
-> Transaction
|
-> Transaction
|
||||||
-> Either String Transaction
|
-> Either String Transaction
|
||||||
balanceTransaction mstyles = fmap fst . balanceTransactionHelper mstyles
|
balanceTransaction mstyles = fmap fst . balanceTransactionHelper mstyles
|
||||||
@ -389,12 +389,12 @@ balanceTransaction mstyles = fmap fst . balanceTransactionHelper mstyles
|
|||||||
-- use one of those instead. It also returns a list of accounts
|
-- use one of those instead. It also returns a list of accounts
|
||||||
-- and amounts that were inferred.
|
-- and amounts that were inferred.
|
||||||
balanceTransactionHelper ::
|
balanceTransactionHelper ::
|
||||||
Maybe (Map.Map CommoditySymbol AmountStyle) -- ^ commodity display styles
|
Maybe (M.Map CommoditySymbol AmountStyle) -- ^ commodity display styles
|
||||||
-> Transaction
|
-> Transaction
|
||||||
-> Either String (Transaction, [(AccountName, MixedAmount)])
|
-> Either String (Transaction, [(AccountName, MixedAmount)])
|
||||||
balanceTransactionHelper mstyles t = do
|
balanceTransactionHelper mstyles t = do
|
||||||
(t', inferredamtsandaccts) <-
|
(t', inferredamtsandaccts) <-
|
||||||
inferBalancingAmount (fromMaybe Map.empty mstyles) $ inferBalancingPrices t
|
inferBalancingAmount (fromMaybe M.empty mstyles) $ inferBalancingPrices t
|
||||||
if isTransactionBalanced mstyles t'
|
if isTransactionBalanced mstyles t'
|
||||||
then Right (txnTieKnot t', inferredamtsandaccts)
|
then Right (txnTieKnot t', inferredamtsandaccts)
|
||||||
else Left $ annotateErrorWithTransaction t' $ nonzerobalanceerror t'
|
else Left $ annotateErrorWithTransaction t' $ nonzerobalanceerror t'
|
||||||
@ -424,7 +424,7 @@ annotateErrorWithTransaction t s = intercalate "\n" [showGenericSourcePos $ tsou
|
|||||||
-- one of them is amountless. If the amounts had price(s) the inferred amount
|
-- one of them is amountless. If the amounts had price(s) the inferred amount
|
||||||
-- have the same price(s), and will be converted to the price commodity.
|
-- have the same price(s), and will be converted to the price commodity.
|
||||||
inferBalancingAmount ::
|
inferBalancingAmount ::
|
||||||
Map.Map CommoditySymbol AmountStyle -- ^ commodity display styles
|
M.Map CommoditySymbol AmountStyle -- ^ commodity display styles
|
||||||
-> Transaction
|
-> Transaction
|
||||||
-> Either String (Transaction, [(AccountName, MixedAmount)])
|
-> Either String (Transaction, [(AccountName, MixedAmount)])
|
||||||
inferBalancingAmount styles t@Transaction{tpostings=ps}
|
inferBalancingAmount styles t@Transaction{tpostings=ps}
|
||||||
@ -684,10 +684,10 @@ tests_Transaction =
|
|||||||
]
|
]
|
||||||
, tests
|
, tests
|
||||||
"inferBalancingAmount"
|
"inferBalancingAmount"
|
||||||
[ (fst <$> inferBalancingAmount Map.empty nulltransaction) `is` Right nulltransaction
|
[ (fst <$> inferBalancingAmount M.empty nulltransaction) `is` Right nulltransaction
|
||||||
, (fst <$> inferBalancingAmount Map.empty nulltransaction{tpostings = ["a" `post` usd (-5), "b" `post` missingamt]}) `is`
|
, (fst <$> inferBalancingAmount M.empty nulltransaction{tpostings = ["a" `post` usd (-5), "b" `post` missingamt]}) `is`
|
||||||
Right nulltransaction{tpostings = ["a" `post` usd (-5), "b" `post` usd 5]}
|
Right nulltransaction{tpostings = ["a" `post` usd (-5), "b" `post` usd 5]}
|
||||||
, (fst <$> inferBalancingAmount Map.empty nulltransaction{tpostings = ["a" `post` usd (-5), "b" `post` (eur 3 @@ usd 4), "c" `post` missingamt]}) `is`
|
, (fst <$> inferBalancingAmount M.empty nulltransaction{tpostings = ["a" `post` usd (-5), "b" `post` (eur 3 @@ usd 4), "c" `post` missingamt]}) `is`
|
||||||
Right nulltransaction{tpostings = ["a" `post` usd (-5), "b" `post` (eur 3 @@ usd 4), "c" `post` usd 1]}
|
Right nulltransaction{tpostings = ["a" `post` usd (-5), "b" `post` (eur 3 @@ usd 4), "c" `post` usd 1]}
|
||||||
]
|
]
|
||||||
, tests
|
, tests
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user