include P amounts in canonicalisation (fixes #131)
Since market price amounts didn't contribute to the canonical commodity styles, they were being reset to the null style. And this propagated to the reported amounts when -V was in effect, causing much confusion. Now, market prices contribute to canonicalisation and the expected styles are preserved even with -V. cf https://github.com/simonmichael/hledger/issues/131#issuecomment-133545140
This commit is contained in:
		
							parent
							
								
									7b8c992f5a
								
							
						
					
					
						commit
						71921135f6
					
				@ -583,13 +583,23 @@ journalConvertAmountsToCost j@Journal{jtxns=ts} = j{jtxns=map fixtransaction ts}
 | 
				
			|||||||
--               Just (UnitPrice ma)  -> c:(concatMap amountCommodities $ amounts ma)
 | 
					--               Just (UnitPrice ma)  -> c:(concatMap amountCommodities $ amounts ma)
 | 
				
			||||||
--               Just (TotalPrice ma) -> c:(concatMap amountCommodities $ amounts ma)
 | 
					--               Just (TotalPrice ma) -> c:(concatMap amountCommodities $ amounts ma)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- | Get all this journal's (mixed) amounts, in the order parsed.
 | 
					-- | Get an ordered list of the amounts in this journal which will
 | 
				
			||||||
journalMixedAmounts :: Journal -> [MixedAmount]
 | 
					-- influence amount style canonicalisation. These are:
 | 
				
			||||||
journalMixedAmounts = map pamount . journalPostings
 | 
					--
 | 
				
			||||||
 | 
					-- * amounts in market price directives (in parse order)
 | 
				
			||||||
-- | Get all this journal's component amounts, roughly in the order parsed.
 | 
					-- * amounts in postings (in parse order)
 | 
				
			||||||
 | 
					--
 | 
				
			||||||
 | 
					-- Amounts in default commodity directives also influence
 | 
				
			||||||
 | 
					-- canonicalisation, but earlier, as amounts are parsed.
 | 
				
			||||||
 | 
					-- Amounts in posting prices are not used for canonicalisation.
 | 
				
			||||||
 | 
					--
 | 
				
			||||||
journalAmounts :: Journal -> [Amount]
 | 
					journalAmounts :: Journal -> [Amount]
 | 
				
			||||||
journalAmounts = concatMap flatten . journalMixedAmounts where flatten (Mixed as) = as
 | 
					journalAmounts j =
 | 
				
			||||||
 | 
					  concat
 | 
				
			||||||
 | 
					   [map mpamount $ jmarketprices j
 | 
				
			||||||
 | 
					   ,concatMap flatten $ map pamount $ journalPostings j
 | 
				
			||||||
 | 
					   ]
 | 
				
			||||||
 | 
					  where flatten (Mixed as) = as
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- | The fully specified date span enclosing the dates (primary or secondary)
 | 
					-- | The fully specified date span enclosing the dates (primary or secondary)
 | 
				
			||||||
-- of all this journal's transactions and postings, or DateSpan Nothing Nothing
 | 
					-- of all this journal's transactions and postings, or DateSpan Nothing Nothing
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										25
									
								
								tests/journal/market-prices.test
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								tests/journal/market-prices.test
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					# market prices defined with the P directive are used by -V/--value.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# 1. market prices (a) are affected by D directives and (b) contribute
 | 
				
			||||||
 | 
					# to amount style canonicalisation.
 | 
				
			||||||
 | 
					# (https://github.com/simonmichael/hledger/issues/131#issuecomment-133545140)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					hledger -f- balance -V
 | 
				
			||||||
 | 
					<<<
 | 
				
			||||||
 | 
					D 1000.00 H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					P 2015/08/14 EEEE   41.66
 | 
				
			||||||
 | 
					P 2015/08/14 FFFF   74.62
 | 
				
			||||||
 | 
					P 2015/08/14 GGGG  32.39
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					2015/08/15
 | 
				
			||||||
 | 
					    a  2.4120 EEEE @@ 100
 | 
				
			||||||
 | 
					    a  0.3350 FFFF @@ 25
 | 
				
			||||||
 | 
					    a  0.7718 GGGG @@ 25
 | 
				
			||||||
 | 
					    b
 | 
				
			||||||
 | 
					>>>
 | 
				
			||||||
 | 
					            150.48 H  a
 | 
				
			||||||
 | 
					           -150.00 H  b
 | 
				
			||||||
 | 
					--------------------
 | 
				
			||||||
 | 
					              0.48 H
 | 
				
			||||||
 | 
					>>>=0
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user