remove the hard-coded rate from Commodity
This commit is contained in:
parent
80beac7d43
commit
0b23598138
@ -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]
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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"
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
2
Tests.hs
2
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.")
|
||||
]
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user