lib: multiBalanceReport derives query from ReportOpts
This commit is contained in:
		
							parent
							
								
									c35d0a8b44
								
							
						
					
					
						commit
						cbacef21eb
					
				| @ -61,7 +61,6 @@ budgetReport ropts' assrt reportspan d j = | |||||||
|     -- and that reports with and without --empty make sense when compared side by side |     -- and that reports with and without --empty make sense when compared side by side | ||||||
|     ropts = ropts' { accountlistmode_ = ALTree } |     ropts = ropts' { accountlistmode_ = ALTree } | ||||||
|     showunbudgeted = empty_ ropts |     showunbudgeted = empty_ ropts | ||||||
|     q = queryFromOpts d ropts |  | ||||||
|     budgetedaccts = |     budgetedaccts = | ||||||
|       dbg2 "budgetedacctsinperiod" $ |       dbg2 "budgetedacctsinperiod" $ | ||||||
|       nub $ |       nub $ | ||||||
| @ -73,9 +72,9 @@ budgetReport ropts' assrt reportspan d j = | |||||||
|     actualj = dbg1With (("actualj"++).show.jtxns)  $ budgetRollUp budgetedaccts showunbudgeted j |     actualj = dbg1With (("actualj"++).show.jtxns)  $ budgetRollUp budgetedaccts showunbudgeted j | ||||||
|     budgetj = dbg1With (("budgetj"++).show.jtxns)  $ budgetJournal assrt ropts reportspan j |     budgetj = dbg1With (("budgetj"++).show.jtxns)  $ budgetJournal assrt ropts reportspan j | ||||||
|     actualreport@(PeriodicReport actualspans _ _) = |     actualreport@(PeriodicReport actualspans _ _) = | ||||||
|         dbg1 "actualreport" $ multiBalanceReport ropts q actualj |         dbg1 "actualreport" $ multiBalanceReport d ropts actualj | ||||||
|     budgetgoalreport@(PeriodicReport _ budgetgoalitems budgetgoaltotals) = |     budgetgoalreport@(PeriodicReport _ budgetgoalitems budgetgoaltotals) = | ||||||
|         dbg1 "budgetgoalreport" $ multiBalanceReport (ropts{empty_=True}) q budgetj |         dbg1 "budgetgoalreport" $ multiBalanceReport d (ropts{empty_=True}) budgetj | ||||||
|     budgetgoalreport' |     budgetgoalreport' | ||||||
|       -- If no interval is specified: |       -- If no interval is specified: | ||||||
|       -- budgetgoalreport's span might be shorter actualreport's due to periodic txns; |       -- budgetgoalreport's span might be shorter actualreport's due to periodic txns; | ||||||
|  | |||||||
| @ -71,13 +71,15 @@ type ClippedAccountName = AccountName | |||||||
| -- (see ReportOpts and CompoundBalanceCommand). | -- (see ReportOpts and CompoundBalanceCommand). | ||||||
| -- hledger's most powerful and useful report, used by the balance | -- hledger's most powerful and useful report, used by the balance | ||||||
| -- command (in multiperiod mode) and (via multiBalanceReport') by the bs/cf/is commands. | -- command (in multiperiod mode) and (via multiBalanceReport') by the bs/cf/is commands. | ||||||
| multiBalanceReport :: ReportOpts -> Query -> Journal -> MultiBalanceReport | multiBalanceReport :: Day -> ReportOpts -> Journal -> MultiBalanceReport | ||||||
| multiBalanceReport ropts q j = multiBalanceReportWith ropts q j (journalPriceOracle j) | multiBalanceReport today ropts j = multiBalanceReportWith ropts (queryFromOpts today ropts) j (journalPriceOracle j) | ||||||
| 
 | 
 | ||||||
| -- | A helper for multiBalanceReport. This one takes an extra argument, a | -- | A helper for multiBalanceReport. This one takes an explicit Query | ||||||
|  | -- instead of deriving one from ReportOpts, and an extra argument, a | ||||||
| -- PriceOracle to be used for looking up market prices. Commands which | -- PriceOracle to be used for looking up market prices. Commands which | ||||||
| -- run multiple reports (bs etc.) can generate the price oracle just once | -- run multiple reports (bs etc.) can generate the price oracle just | ||||||
| -- for efficiency, passing it to each report by calling this function directly. | -- once for efficiency, passing it to each report by calling this | ||||||
|  | -- function directly. | ||||||
| multiBalanceReportWith :: ReportOpts -> Query -> Journal -> PriceOracle -> MultiBalanceReport | multiBalanceReportWith :: ReportOpts -> Query -> Journal -> PriceOracle -> MultiBalanceReport | ||||||
| multiBalanceReportWith ropts@ReportOpts{..} q j priceoracle = | multiBalanceReportWith ropts@ReportOpts{..} q j priceoracle = | ||||||
|   (if invert_ then prNegate else id) $ |   (if invert_ then prNegate else id) $ | ||||||
| @ -358,7 +360,7 @@ multiBalanceReportWith ropts@ReportOpts{..} q j priceoracle = | |||||||
| balanceReportFromMultiBalanceReport :: ReportOpts -> Query -> Journal -> BalanceReport | balanceReportFromMultiBalanceReport :: ReportOpts -> Query -> Journal -> BalanceReport | ||||||
| balanceReportFromMultiBalanceReport opts q j = (rows', total) | balanceReportFromMultiBalanceReport opts q j = (rows', total) | ||||||
|   where |   where | ||||||
|     PeriodicReport _ rows (PeriodicReportRow _ _ totals _ _) = multiBalanceReport opts q j |     PeriodicReport _ rows (PeriodicReportRow _ _ totals _ _) = multiBalanceReportWith opts q j (journalPriceOracle j) | ||||||
|     rows' = [( a |     rows' = [( a | ||||||
|              , if flat_ opts then a else accountLeafName a   -- BalanceReport expects full account name here with --flat |              , if flat_ opts then a else accountLeafName a   -- BalanceReport expects full account name here with --flat | ||||||
|              , if tree_ opts then d-1 else 0  -- BalanceReport uses 0-based account depths |              , if tree_ opts then d-1 else 0  -- BalanceReport uses 0-based account depths | ||||||
| @ -391,7 +393,7 @@ tests_MultiBalanceReport = tests "MultiBalanceReport" [ | |||||||
|     amt0 = Amount {acommodity="$", aquantity=0, aprice=Nothing, astyle=AmountStyle {ascommodityside = L, ascommodityspaced = False, asprecision = 2, asdecimalpoint = Just '.', asdigitgroups = Nothing}, aismultiplier=False} |     amt0 = Amount {acommodity="$", aquantity=0, aprice=Nothing, astyle=AmountStyle {ascommodityside = L, ascommodityspaced = False, asprecision = 2, asdecimalpoint = Just '.', asdigitgroups = Nothing}, aismultiplier=False} | ||||||
|     (opts,journal) `gives` r = do |     (opts,journal) `gives` r = do | ||||||
|       let (eitems, etotal) = r |       let (eitems, etotal) = r | ||||||
|           (PeriodicReport _ aitems atotal) = multiBalanceReport opts (queryFromOpts nulldate opts) journal |           (PeriodicReport _ aitems atotal) = multiBalanceReport nulldate opts journal | ||||||
|           showw (PeriodicReportRow acct indent lAmt amt amt') |           showw (PeriodicReportRow acct indent lAmt amt amt') | ||||||
|               = (acct, accountLeafName acct, indent, map showMixedAmountDebug lAmt, showMixedAmountDebug amt, showMixedAmountDebug amt') |               = (acct, accountLeafName acct, indent, map showMixedAmountDebug lAmt, showMixedAmountDebug amt, showMixedAmountDebug amt') | ||||||
|       (map showw aitems) @?= (map showw eitems) |       (map showw aitems) @?= (map showw eitems) | ||||||
|  | |||||||
| @ -327,7 +327,7 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts@ReportOpts{..}} j = do | |||||||
| 
 | 
 | ||||||
|       else |       else | ||||||
|         if multiperiod then do  -- multi period balance report |         if multiperiod then do  -- multi period balance report | ||||||
|           let report = multiBalanceReport ropts (queryFromOpts d ropts) j |           let report = multiBalanceReport d ropts j | ||||||
|               render = case fmt of |               render = case fmt of | ||||||
|                 "txt"  -> multiBalanceReportAsText ropts |                 "txt"  -> multiBalanceReportAsText ropts | ||||||
|                 "csv"  -> (++"\n") . printCSV . multiBalanceReportAsCsv ropts |                 "csv"  -> (++"\n") . printCSV . multiBalanceReportAsCsv ropts | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user