journal: txn modifier multipliers multiply total-priced amounts (#928)
A different approach: instead of converting to unit prices and fiddling with the display precision, just multiply the total prices by the same multiplier (and keep them positive). This seems a little more natural. I'm not sure if one of these will be more robust than the other.
This commit is contained in:
		
							parent
							
								
									d7919003ae
								
							
						
					
					
						commit
						b00aa32d7b
					
				| @ -92,12 +92,14 @@ tmPostingRuleToFunction pr = | ||||
|         Nothing -> const $ pamount pr | ||||
|         Just n  -> \p -> | ||||
|           -- Multiply the old posting's amount by the posting rule's multiplier. | ||||
|           -- Its display precision will be increased if needed to show all digits. | ||||
|           let | ||||
|             pramount = dbg6 "pramount" $ head $ amounts $ pamount pr | ||||
|             matchedamount = dbg6 "matchedamount" $ pamount p | ||||
|             unitpricedmatchedamount = dbg6 "unitpricedmatchedamount" $ mixedAmountTotalPriceToUnitPrice matchedamount | ||||
|             Mixed as = dbg6 "scaledmatchedamount" $ n `multiplyMixedAmount` unitpricedmatchedamount  | ||||
|             -- Handle a matched amount with a total price carefully so as to keep the transaction balanced (#928). | ||||
|             -- Approach 1: convert to a unit price and increase the display precision slightly | ||||
|             -- Mixed as = dbg6 "multipliedamount" $ n `multiplyMixedAmount` mixedAmountTotalPriceToUnitPrice matchedamount  | ||||
|             -- Approach 2: multiply the total price (keeping it positive) as well as the quantity  | ||||
|             Mixed as = dbg6 "multipliedamount" $ n `multiplyMixedAmountAndPrice` matchedamount  | ||||
|           in | ||||
|             case acommodity pramount of | ||||
|               "" -> Mixed as | ||||
|  | ||||
| @ -35,14 +35,21 @@ $ hledger -f- print --auto | ||||
| $ hledger -f- print --auto | ||||
| 2018/01/01 | ||||
|     Expenses:Joint:Widgets     $100.00 @@ £50 | ||||
|     Expenses:Joint            $-100.00 @ £0.5 | ||||
|     Liabilities:Joint:Bob       $50.00 @ £0.5 | ||||
|     Liabilities:Joint:Bill      $50.00 @ £0.5 | ||||
|     Expenses:Joint            $-100.00 @@ £50 | ||||
|     Liabilities:Joint:Bob       $50.00 @@ £25 | ||||
|     Liabilities:Joint:Bill      $50.00 @@ £25 | ||||
|     Assets:Joint:Bank                 £-50.00 | ||||
| 
 | ||||
| >=0 | ||||
| # alternate approach: convert to unit prices | ||||
| #2018/01/01 | ||||
| #    Expenses:Joint:Widgets     $100.00 @@ £50 | ||||
| #    Expenses:Joint            $-100.00 @ £0.5 | ||||
| #    Liabilities:Joint:Bob       $50.00 @ £0.5 | ||||
| #    Liabilities:Joint:Bill      $50.00 @ £0.5 | ||||
| #    Assets:Joint:Bank                 £-50.00 | ||||
| 
 | ||||
| # Generating auto postings from an implicitly-priced amount. Same as above. | ||||
| # Generating auto postings from an implicitly-priced amount. Should work like the above. | ||||
| < | ||||
| = ^Expenses:Joint | ||||
|     Expenses:Joint                                               *-1 | ||||
| @ -56,9 +63,9 @@ $ hledger -f- print --auto | ||||
| $ hledger -f- print --auto | ||||
| 2018/01/01 | ||||
|     Expenses:Joint:Widgets            $100.00 | ||||
|     Expenses:Joint            $-100.00 @ £0.5 | ||||
|     Liabilities:Joint:Bob       $50.00 @ £0.5 | ||||
|     Liabilities:Joint:Bill      $50.00 @ £0.5 | ||||
|     Expenses:Joint            $-100.00 @@ £50 | ||||
|     Liabilities:Joint:Bob       $50.00 @@ £25 | ||||
|     Liabilities:Joint:Bill      $50.00 @@ £25 | ||||
|     Assets:Joint:Bank                 £-50.00 | ||||
| 
 | ||||
| >=0 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user