lib: When inferring total prices, use the precision of toamount, rather than NaturalPrecision.
This commit is contained in:
		
							parent
							
								
									686a0871a9
								
							
						
					
					
						commit
						d1467d4766
					
				| @ -584,7 +584,7 @@ priceInferrerFor t pt = maybe id inferprice inferFromAndTo | ||||
|         -- If only one Amount in the posting list matches fromamount we can use TotalPrice. | ||||
|         -- Otherwise divide the conversion equally among the Amounts by using a unit price. | ||||
|         conversionprice = case filter (== acommodity fromamount) pcommodities of | ||||
|             [_] -> TotalPrice $ negate toamount  `withPrecision` NaturalPrecision | ||||
|             [_] -> TotalPrice $ negate toamount | ||||
|             _   -> UnitPrice  $ negate unitprice `withPrecision` unitprecision | ||||
| 
 | ||||
|         unitprice     = aquantity fromamount `divideAmount` toamount | ||||
| @ -918,7 +918,7 @@ tests_Transaction = | ||||
|                 [ posting {paccount = "a", pamount = mixedAmount (usd 1.35)} | ||||
|                 , posting {paccount = "b", pamount = mixedAmount (eur (-1))} | ||||
|                 ])) @?= | ||||
|           Right (mixedAmount $ usd 1.35 @@ (eur 1 `withPrecision` NaturalPrecision)) | ||||
|           Right (mixedAmount $ usd 1.35 @@ eur 1) | ||||
|         ,test "balanceTransaction balances based on cost if there are unit prices" $ | ||||
|           assertRight $ | ||||
|           balanceTransaction | ||||
|  | ||||
| @ -231,9 +231,9 @@ $ hledger -f- print --auto | ||||
| $ hledger -f- print --auto | ||||
| 2018-01-01  ; modified: | ||||
|     Expenses:Joint:Widgets               $100.00 | ||||
|     Expenses:Joint            $-100.00 @@ £50  ; generated-posting: = ^Expenses:Joint | ||||
|     Liabilities:Joint:Bob       $50.00 @@ £25  ; generated-posting: = ^Expenses:Joint | ||||
|     Liabilities:Joint:Bill      $50.00 @@ £25  ; generated-posting: = ^Expenses:Joint | ||||
|     Expenses:Joint            $-100.00 @@ £50.00  ; generated-posting: = ^Expenses:Joint | ||||
|     Liabilities:Joint:Bob       $50.00 @@ £25.00  ; generated-posting: = ^Expenses:Joint | ||||
|     Liabilities:Joint:Bill      $50.00 @@ £25.00  ; generated-posting: = ^Expenses:Joint | ||||
|     Assets:Joint:Bank                    £-50.00 | ||||
| 
 | ||||
| >=0 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user