fix/rename convertMixedAmountToCommodity, yay release tests
This commit is contained in:
parent
10fd7ebc42
commit
b32ee2fa04
@ -106,7 +106,7 @@ sameSignNonZero is | null nzs = ([], 1)
|
|||||||
|
|
||||||
-- | Convert all quantities of MixedAccount to a single commodity
|
-- | Convert all quantities of MixedAccount to a single commodity
|
||||||
amountValue :: MixedAmount -> Double
|
amountValue :: MixedAmount -> Double
|
||||||
amountValue = quantity . convertMixedAmountToSimilarCommodity unknown
|
amountValue = quantity . mixedAmountWithCommodity unknown
|
||||||
|
|
||||||
-- | Generate a tree of account names together with their balances.
|
-- | Generate a tree of account names together with their balances.
|
||||||
-- The balance of account is decremented by the balance of its subaccounts
|
-- The balance of account is decremented by the balance of its subaccounts
|
||||||
|
|||||||
@ -44,6 +44,7 @@ price-preserving (for amounts with the same prices) or price-ignoring
|
|||||||
module Hledger.Data.Amount (
|
module Hledger.Data.Amount (
|
||||||
-- * Amount
|
-- * Amount
|
||||||
nullamt,
|
nullamt,
|
||||||
|
amountWithCommodity,
|
||||||
canonicaliseAmountCommodity,
|
canonicaliseAmountCommodity,
|
||||||
setAmountPrecision,
|
setAmountPrecision,
|
||||||
-- ** arithmetic
|
-- ** arithmetic
|
||||||
@ -61,6 +62,7 @@ module Hledger.Data.Amount (
|
|||||||
amounts,
|
amounts,
|
||||||
normaliseMixedAmount,
|
normaliseMixedAmount,
|
||||||
canonicaliseMixedAmountCommodity,
|
canonicaliseMixedAmountCommodity,
|
||||||
|
mixedAmountWithCommodity,
|
||||||
setMixedAmountPrecision,
|
setMixedAmountPrecision,
|
||||||
-- ** arithmetic
|
-- ** arithmetic
|
||||||
costOfMixedAmount,
|
costOfMixedAmount,
|
||||||
@ -117,12 +119,12 @@ nullamt = Amount unknown 0 Nothing
|
|||||||
-- The highest precision of either amount is preserved in the result.
|
-- The highest precision of either amount is preserved in the result.
|
||||||
similarAmountsOp :: (Double -> Double -> Double) -> Amount -> Amount -> Amount
|
similarAmountsOp :: (Double -> Double -> Double) -> Amount -> Amount -> Amount
|
||||||
similarAmountsOp op a@(Amount Commodity{precision=ap} _ _) (Amount bc@Commodity{precision=bp} bq _) =
|
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
|
-- | Convert an amount to the specified commodity, ignoring and discarding
|
||||||
-- any assigned prices and assuming an exchange rate of 1.
|
-- any assigned prices and assuming an exchange rate of 1.
|
||||||
convertAmountToCommodity :: Commodity -> Amount -> Amount
|
amountWithCommodity :: Commodity -> Amount -> Amount
|
||||||
convertAmountToCommodity c (Amount _ q _) = Amount c q Nothing
|
amountWithCommodity c (Amount _ q _) = Amount c q Nothing
|
||||||
|
|
||||||
-- | Convert an amount to the commodity of its assigned price, if any. Notes:
|
-- | 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)
|
-- - 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
|
isReallyZeroMixedAmountCost = isReallyZeroMixedAmount . costOfMixedAmount
|
||||||
|
|
||||||
-- -- | Convert a mixed amount to the specified commodity, assuming an exchange rate of 1.
|
-- -- | Convert a mixed amount to the specified commodity, assuming an exchange rate of 1.
|
||||||
-- convertMixedAmountToCommodity :: Commodity -> MixedAmount -> Amount
|
mixedAmountWithCommodity :: Commodity -> MixedAmount -> Amount
|
||||||
-- convertMixedAmountToCommodity c (Mixed as) = Amount c total Nothing
|
mixedAmountWithCommodity c (Mixed as) = Amount c total Nothing
|
||||||
-- where
|
where
|
||||||
-- total = sum $ map (quantity . convertAmountToCommodity c) as
|
total = sum $ map (quantity . amountWithCommodity c) as
|
||||||
|
|
||||||
-- -- | MixedAmount derived Eq instance in Types.hs doesn't know that we
|
-- -- | 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.
|
-- -- want $0 = EUR0 = 0. Yet we don't want to drag all this code over there.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user