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 | -- temporary value for partial entries | ||||||
| autoamt :: MixedAmount | 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. | -- 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. | -- convenient amount and commodity constructors, for tests etc. | ||||||
| 
 | 
 | ||||||
| dollar  = Commodity {symbol="$",side=L,spaced=False,comma=False,precision=2,rate=1} | dollar  = Commodity {symbol="$",side=L,spaced=False,comma=False,precision=2} | ||||||
| euro    = Commodity {symbol="EUR",side=L,spaced=False,comma=False,precision=2,rate=0.760383} | euro    = Commodity {symbol="EUR",side=L,spaced=False,comma=False,precision=2} | ||||||
| pound   = Commodity {symbol="£",side=L,spaced=False,comma=False,precision=2,rate=0.512527} | pound   = Commodity {symbol="£",side=L,spaced=False,comma=False,precision=2} | ||||||
| hour    = Commodity {symbol="h",side=R,spaced=False,comma=False,precision=1,rate=100} | hour    = Commodity {symbol="h",side=R,spaced=False,comma=False,precision=1} | ||||||
| 
 | 
 | ||||||
| dollars  = Amount dollar | dollars  = Amount dollar | ||||||
| euros    = Amount euro | euros    = Amount euro | ||||||
| @ -38,5 +38,5 @@ comm symbol = Map.findWithDefault (error "commodity lookup failed") symbol defau | |||||||
| 
 | 
 | ||||||
| -- | Find the conversion rate between two commodities. | -- | Find the conversion rate between two commodities. | ||||||
| conversionRate :: Commodity -> Commodity -> Double | conversionRate :: Commodity -> Commodity -> Double | ||||||
| conversionRate oldc newc = (rate newc) / (rate oldc) | conversionRate oldc newc = 1 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -314,7 +314,7 @@ leftsymbolamount = do | |||||||
|   sym <- commoditysymbol  |   sym <- commoditysymbol  | ||||||
|   sp <- many spacenonewline |   sp <- many spacenonewline | ||||||
|   (q,p,comma) <- amountquantity |   (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] |   return $ Mixed [Amount c q] | ||||||
|   <?> "left-symbol amount" |   <?> "left-symbol amount" | ||||||
| 
 | 
 | ||||||
| @ -323,14 +323,14 @@ rightsymbolamount = do | |||||||
|   (q,p,comma) <- amountquantity |   (q,p,comma) <- amountquantity | ||||||
|   sp <- many spacenonewline |   sp <- many spacenonewline | ||||||
|   sym <- commoditysymbol |   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] |   return $ Mixed [Amount c q] | ||||||
|   <?> "right-symbol amount" |   <?> "right-symbol amount" | ||||||
| 
 | 
 | ||||||
| nosymbolamount :: Parser MixedAmount | nosymbolamount :: Parser MixedAmount | ||||||
| nosymbolamount = do | nosymbolamount = do | ||||||
|   (q,p,comma) <- amountquantity |   (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] |   return $ Mixed [Amount c q] | ||||||
|   <?> "no-symbol amount" |   <?> "no-symbol amount" | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -26,9 +26,7 @@ data Commodity = Commodity { | |||||||
|       side :: Side,      -- ^ should the symbol appear on the left or the right |       side :: Side,      -- ^ should the symbol appear on the left or the right | ||||||
|       spaced :: Bool,    -- ^ should there be a space between symbol and quantity |       spaced :: Bool,    -- ^ should there be a space between symbol and quantity | ||||||
|       comma :: Bool,     -- ^ should thousands be comma-separated |       comma :: Bool,     -- ^ should thousands be comma-separated | ||||||
|       precision :: Int,  -- ^ number of decimal places to display |       precision :: Int   -- ^ number of decimal places to display | ||||||
| 
 |  | ||||||
|       rate :: Double     -- ^ the current (hard-coded) conversion rate against the dollar |  | ||||||
|     } deriving (Eq,Show) |     } deriving (Eq,Show) | ||||||
| 
 | 
 | ||||||
| data Amount = Amount { | data Amount = Amount { | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								Tests.hs
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								Tests.hs
									
									
									
									
									
								
							| @ -104,7 +104,7 @@ unittests = TestList [ | |||||||
|   , |   , | ||||||
|   "transactionamount"       ~: do |   "transactionamount"       ~: do | ||||||
|     assertparseequal (Mixed [dollars 47.18]) (parsewith transactionamount " $47.18") |     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