print: be sure to value all postings; -V/-X/--value now imply -x
Previously -B implied -x; now any of the valuation flags do. This avoids a bug where print -V of a transaction with an implicit commodity conversion would convert only some of its postings to value. Also, more valuation tests.
This commit is contained in:
		
							parent
							
								
									ae9d8d6e56
								
							
						
					
					
						commit
						dad4d9b662
					
				| @ -15,6 +15,7 @@ module Hledger.Cli.Commands.Print ( | ||||
| ) | ||||
| where | ||||
| 
 | ||||
| import Data.Maybe (isJust) | ||||
| import Data.Text (Text) | ||||
| import qualified Data.Text as T | ||||
| import System.Console.CmdArgs.Explicit | ||||
| @ -59,14 +60,18 @@ printEntries opts@CliOpts{reportopts_=ropts} j = do | ||||
|   writeOutput opts $ render $ entriesReport ropts' q j | ||||
| 
 | ||||
| entriesReportAsText :: CliOpts -> EntriesReport -> String | ||||
| entriesReportAsText opts = concatMap (showTransaction . gettxn) | ||||
| entriesReportAsText opts = concatMap (showTransaction . whichtxn) | ||||
|   where | ||||
|     gettxn | useexplicittxn = id                   -- use fully inferred amounts & txn prices | ||||
|            | otherwise      = originalTransaction  -- use original as-written amounts/txn prices | ||||
|     -- Original vs inferred transactions/postings were causing problems here, disabling -B (#551). | ||||
|     -- Use the explicit one if -B or -x are active. | ||||
|     -- This passes tests; does it also mean -B sometimes shows missing amounts unnecessarily ? | ||||
|     useexplicittxn = boolopt "explicit" (rawopts_ opts) || (valuationTypeIsCost $ reportopts_ opts) | ||||
|     whichtxn | ||||
|       -- With -x, use the fully-inferred txn with all amounts & txn prices explicit. | ||||
|       | boolopt "explicit" (rawopts_ opts) | ||||
|         -- Or also, if any of -B/-V/-X/--value are active. | ||||
|         -- Because of #551, and because of print -V valuing only one | ||||
|         -- posting when there's an implicit txn price. | ||||
|         -- So -B/-V/-X/--value implies -x. Is this ok ? | ||||
|         || (isJust $ value_ $ reportopts_ opts) = id | ||||
|       -- By default, use the original as-written-in-the-journal txn. | ||||
|       | otherwise = originalTransaction | ||||
| 
 | ||||
| -- Replace this transaction's postings with the original postings if any, but keep the | ||||
| -- current possibly rewritten account names. | ||||
|  | ||||
| @ -41,6 +41,7 @@ Similarly, when a transaction price is implied but not written, it will not appe | ||||
| You can use the `-x`/`--explicit` flag to make all amounts and transaction prices explicit,  | ||||
| which can be useful for troubleshooting or for making your journal more readable and | ||||
| robust against data entry errors. | ||||
| `-x` is also implied by using any of `-B`,`-V`,`-X`,`--value`. | ||||
| 
 | ||||
| Note, `-x`/`--explicit` will cause postings with a multi-commodity amount | ||||
| (these can arise when a multi-commodity transaction has an implicit amount) | ||||
|  | ||||
| @ -566,3 +566,68 @@ Budget performance in 2000q1, valued at 2000-01-15: | ||||
|  a || 5 B [  50% of 10 B]  5 B [  50% of 10 B]  5 B [  50% of 10 B]  15 B [  50% of 30 B]  5 B [  50% of 10 B]  | ||||
| ---++---------------------------------------------------------------------------------------------------------- | ||||
|    || 5 B [  50% of 10 B]  5 B [  50% of 10 B]  5 B [  50% of 10 B]  15 B [  50% of 30 B]  5 B [  50% of 10 B]  | ||||
| 
 | ||||
| # 50. --value=then with --historical. How is the starting total valued ? | ||||
| # Currently not supported. | ||||
| < | ||||
| P 2020-01-01 A 1 B | ||||
| P 2020-02-01 A 2 B | ||||
| P 2020-03-01 A 3 B | ||||
| P 2020-04-01 A 4 B | ||||
| 
 | ||||
| 2020-01-01 | ||||
|    (a)  1 A | ||||
| 
 | ||||
| 2020-02-01 | ||||
|    (a)  1 A | ||||
| 
 | ||||
| 2020-03-01 | ||||
|    (a)  1 A | ||||
| 
 | ||||
| 2020-04-01 | ||||
|    (a)  1 A | ||||
| 
 | ||||
| $ hledger -f- reg --value=then -b 2020-03 -H | ||||
| >2 /not yet implemented/ | ||||
| >=1 | ||||
| 
 | ||||
| # 51. --value=then with a report interval. How are the summary amounts valued ? | ||||
| # Currently each interval's unvalued sum is valued on its first day. | ||||
| < | ||||
| P 2020-01-01 A 1 B | ||||
| P 2020-02-01 A 2 B | ||||
| P 2020-03-01 A 3 B | ||||
| P 2020-04-01 A 4 B | ||||
| 
 | ||||
| 2020-01-01 | ||||
|    (a)  1 A | ||||
| 
 | ||||
| 2020-02-01 | ||||
|    (a)  1 A | ||||
| 
 | ||||
| 2020-03-01 | ||||
|    (a)  1 A | ||||
| 
 | ||||
| 2020-04-01 | ||||
|    (a)  1 A | ||||
| 
 | ||||
| $ hledger -f- reg --value=then -Q | ||||
| 2020q1                  a                                      3 B           3 B | ||||
| 2020q2                  a                                      4 B           7 B | ||||
| >=0 | ||||
| 
 | ||||
| # 52. print --value should affect all postings, including when there's an implicit transaction price | ||||
| < | ||||
| P 2020-01-01 A 1 C | ||||
| P 2020-01-01 B 1 C | ||||
| 
 | ||||
| 2020-01-01 | ||||
|    a   1 A | ||||
|    b  -1 B | ||||
| 
 | ||||
| $ hledger -f- print -V | ||||
| 2020-01-01 | ||||
|     a             1 C | ||||
|     b            -1 C | ||||
| 
 | ||||
| >=0 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user