fix/rename convertMixedAmountToCommodity, yay release tests

This commit is contained in:
Simon Michael 2011-09-02 00:42:41 +00:00
parent 10fd7ebc42
commit b32ee2fa04
2 changed files with 10 additions and 8 deletions

View File

@ -106,7 +106,7 @@ sameSignNonZero is | null nzs = ([], 1)
-- | Convert all quantities of MixedAccount to a single commodity
amountValue :: MixedAmount -> Double
amountValue = quantity . convertMixedAmountToSimilarCommodity unknown
amountValue = quantity . mixedAmountWithCommodity unknown
-- | Generate a tree of account names together with their balances.
-- The balance of account is decremented by the balance of its subaccounts

View File

@ -44,6 +44,7 @@ price-preserving (for amounts with the same prices) or price-ignoring
module Hledger.Data.Amount (
-- * Amount
nullamt,
amountWithCommodity,
canonicaliseAmountCommodity,
setAmountPrecision,
-- ** arithmetic
@ -61,6 +62,7 @@ module Hledger.Data.Amount (
amounts,
normaliseMixedAmount,
canonicaliseMixedAmountCommodity,
mixedAmountWithCommodity,
setMixedAmountPrecision,
-- ** arithmetic
costOfMixedAmount,
@ -117,12 +119,12 @@ nullamt = Amount unknown 0 Nothing
-- The highest precision of either amount is preserved in the result.
similarAmountsOp :: (Double -> Double -> Double) -> Amount -> Amount -> Amount
similarAmountsOp op a@(Amount Commodity{precision=ap} _ _) (Amount bc@Commodity{precision=bp} bq _) =
Amount bc{precision=max ap bp} (quantity (convertAmountToCommodity bc a) `op` bq) Nothing
Amount bc{precision=max ap bp} (quantity (amountWithCommodity bc a) `op` bq) Nothing
-- | Convert an amount to the specified commodity, ignoring and discarding
-- any assigned prices and assuming an exchange rate of 1.
convertAmountToCommodity :: Commodity -> Amount -> Amount
convertAmountToCommodity c (Amount _ q _) = Amount c q Nothing
amountWithCommodity :: Commodity -> Amount -> Amount
amountWithCommodity c (Amount _ q _) = Amount c q Nothing
-- | Convert an amount to the commodity of its assigned price, if any. Notes:
-- - price amounts must be MixedAmounts with exactly one component Amount (or there will be a runtime error)
@ -327,10 +329,10 @@ isReallyZeroMixedAmountCost :: MixedAmount -> Bool
isReallyZeroMixedAmountCost = isReallyZeroMixedAmount . costOfMixedAmount
-- -- | Convert a mixed amount to the specified commodity, assuming an exchange rate of 1.
-- convertMixedAmountToCommodity :: Commodity -> MixedAmount -> Amount
-- convertMixedAmountToCommodity c (Mixed as) = Amount c total Nothing
-- where
-- total = sum $ map (quantity . convertAmountToCommodity c) as
mixedAmountWithCommodity :: Commodity -> MixedAmount -> Amount
mixedAmountWithCommodity c (Mixed as) = Amount c total Nothing
where
total = sum $ map (quantity . amountWithCommodity c) as
-- -- | MixedAmount derived Eq instance in Types.hs doesn't know that we
-- -- want $0 = EUR0 = 0. Yet we don't want to drag all this code over there.