From 0b23598138099999c632cd79e8902c1d46907cd0 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 18 Oct 2008 10:46:49 +0000 Subject: [PATCH] remove the hard-coded rate from Commodity --- Ledger/Amount.hs | 2 +- Ledger/Commodity.hs | 12 ++++++------ Ledger/Parse.hs | 6 +++--- Ledger/Types.hs | 4 +--- Tests.hs | 2 +- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/Ledger/Amount.hs b/Ledger/Amount.hs index 8606081a3..1df13441b 100644 --- a/Ledger/Amount.hs +++ b/Ledger/Amount.hs @@ -140,4 +140,4 @@ nullamt = Mixed [] -- temporary value for partial entries autoamt :: MixedAmount -autoamt = Mixed [Amount (Commodity {symbol="AUTO",side=L,spaced=False,comma=False,precision=0,rate=1}) 0] +autoamt = Mixed [Amount (Commodity {symbol="AUTO",side=L,spaced=False,comma=False,precision=0}) 0] diff --git a/Ledger/Commodity.hs b/Ledger/Commodity.hs index 67fbc3ddd..5bf94ccc9 100644 --- a/Ledger/Commodity.hs +++ b/Ledger/Commodity.hs @@ -14,14 +14,14 @@ import Ledger.Types -- for nullamt, autoamt, etc. -unknown = Commodity {symbol="",side=L,spaced=False,comma=False,precision=0,rate=1} +unknown = Commodity {symbol="",side=L,spaced=False,comma=False,precision=0} -- convenient amount and commodity constructors, for tests etc. -dollar = Commodity {symbol="$",side=L,spaced=False,comma=False,precision=2,rate=1} -euro = Commodity {symbol="EUR",side=L,spaced=False,comma=False,precision=2,rate=0.760383} -pound = Commodity {symbol="£",side=L,spaced=False,comma=False,precision=2,rate=0.512527} -hour = Commodity {symbol="h",side=R,spaced=False,comma=False,precision=1,rate=100} +dollar = Commodity {symbol="$",side=L,spaced=False,comma=False,precision=2} +euro = Commodity {symbol="EUR",side=L,spaced=False,comma=False,precision=2} +pound = Commodity {symbol="£",side=L,spaced=False,comma=False,precision=2} +hour = Commodity {symbol="h",side=R,spaced=False,comma=False,precision=1} dollars = Amount dollar euros = Amount euro @@ -38,5 +38,5 @@ comm symbol = Map.findWithDefault (error "commodity lookup failed") symbol defau -- | Find the conversion rate between two commodities. conversionRate :: Commodity -> Commodity -> Double -conversionRate oldc newc = (rate newc) / (rate oldc) +conversionRate oldc newc = 1 diff --git a/Ledger/Parse.hs b/Ledger/Parse.hs index a58cf96e9..89d7db77b 100644 --- a/Ledger/Parse.hs +++ b/Ledger/Parse.hs @@ -314,7 +314,7 @@ leftsymbolamount = do sym <- commoditysymbol sp <- many spacenonewline (q,p,comma) <- amountquantity - let c = Commodity {symbol=sym,side=L,spaced=not $ null sp,comma=comma,precision=p,rate=1} + let c = Commodity {symbol=sym,side=L,spaced=not $ null sp,comma=comma,precision=p} return $ Mixed [Amount c q] "left-symbol amount" @@ -323,14 +323,14 @@ rightsymbolamount = do (q,p,comma) <- amountquantity sp <- many spacenonewline sym <- commoditysymbol - let c = Commodity {symbol=sym,side=R,spaced=not $ null sp,comma=comma,precision=p,rate=1} + let c = Commodity {symbol=sym,side=R,spaced=not $ null sp,comma=comma,precision=p} return $ Mixed [Amount c q] "right-symbol amount" nosymbolamount :: Parser MixedAmount nosymbolamount = do (q,p,comma) <- amountquantity - let c = Commodity {symbol="",side=L,spaced=False,comma=comma,precision=p,rate=1} + let c = Commodity {symbol="",side=L,spaced=False,comma=comma,precision=p} return $ Mixed [Amount c q] "no-symbol amount" diff --git a/Ledger/Types.hs b/Ledger/Types.hs index d62a60123..aa9a23834 100644 --- a/Ledger/Types.hs +++ b/Ledger/Types.hs @@ -26,9 +26,7 @@ data Commodity = Commodity { side :: Side, -- ^ should the symbol appear on the left or the right spaced :: Bool, -- ^ should there be a space between symbol and quantity comma :: Bool, -- ^ should thousands be comma-separated - precision :: Int, -- ^ number of decimal places to display - - rate :: Double -- ^ the current (hard-coded) conversion rate against the dollar + precision :: Int -- ^ number of decimal places to display } deriving (Eq,Show) data Amount = Amount { diff --git a/Tests.hs b/Tests.hs index ec2514a60..aea0deb34 100644 --- a/Tests.hs +++ b/Tests.hs @@ -104,7 +104,7 @@ unittests = TestList [ , "transactionamount" ~: do assertparseequal (Mixed [dollars 47.18]) (parsewith transactionamount " $47.18") - assertparseequal (Mixed [Amount (Commodity {symbol="$",side=L,spaced=False,comma=False,precision=0,rate=1}) 1]) (parsewith transactionamount " $1.") + assertparseequal (Mixed [Amount (Commodity {symbol="$",side=L,spaced=False,comma=False,precision=0}) 1]) (parsewith transactionamount " $1.") ] ------------------------------------------------------------------------------