budget: allow multi-interval budgets again
Budgets were restricted to a single interval in 1.9, but this was a mistake. This restores the 1.5 behaviour, where a budget can be built up from multiple periodic transactions with different intervals.
This commit is contained in:
		
							parent
							
								
									e2c55aafa9
								
							
						
					
					
						commit
						0c140d7238
					
				@ -73,21 +73,19 @@ budgetReport ropts assrt showunbudgeted reportspan d j =
 | 
				
			|||||||
    dbg1 "budgetreport" $ 
 | 
					    dbg1 "budgetreport" $ 
 | 
				
			||||||
    combineBudgetAndActual budgetgoalreport actualreport
 | 
					    combineBudgetAndActual budgetgoalreport actualreport
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- | Select all periodic transactions from the given journal which
 | 
					-- | Use all periodic transactions in the journal to generate 
 | 
				
			||||||
-- match the requested report interval, and use them to generate
 | 
					-- budget transactions in the specified report period.
 | 
				
			||||||
-- budget transactions (like forecast transactions) in the specified
 | 
					-- Budget transactions are similar to forecast transactions except
 | 
				
			||||||
-- report period (calculated in IO and passed in).
 | 
					-- their purpose is to set goal amounts (of change) per account and period.
 | 
				
			||||||
budgetJournal :: Bool -> ReportOpts -> DateSpan -> Journal -> Journal
 | 
					budgetJournal :: Bool -> ReportOpts -> DateSpan -> Journal -> Journal
 | 
				
			||||||
budgetJournal assrt ropts reportspan j =
 | 
					budgetJournal assrt _ropts reportspan j =
 | 
				
			||||||
  either error' id $ journalBalanceTransactions assrt j{ jtxns = budgetts }
 | 
					  either error' id $ journalBalanceTransactions assrt j{ jtxns = budgetts }
 | 
				
			||||||
  where
 | 
					  where
 | 
				
			||||||
    budgetinterval = dbg2 "budgetinterval" $ interval_ ropts
 | 
					 | 
				
			||||||
    budgetspan = dbg2 "budgetspan" $ reportspan
 | 
					    budgetspan = dbg2 "budgetspan" $ reportspan
 | 
				
			||||||
    budgetts =
 | 
					    budgetts =
 | 
				
			||||||
      dbg1 "budgetts" $
 | 
					      dbg1 "budgetts" $
 | 
				
			||||||
      [makeBudgetTxn t
 | 
					      [makeBudgetTxn t
 | 
				
			||||||
      | pt <- jperiodictxns j
 | 
					      | pt <- jperiodictxns j
 | 
				
			||||||
      , periodTransactionInterval pt == Just budgetinterval
 | 
					 | 
				
			||||||
      , t <- runPeriodicTransaction pt budgetspan
 | 
					      , t <- runPeriodicTransaction pt budgetspan
 | 
				
			||||||
      ]
 | 
					      ]
 | 
				
			||||||
    makeBudgetTxn t = txnTieKnot $ t { tdescription = T.pack "Budget transaction" }
 | 
					    makeBudgetTxn t = txnTieKnot $ t { tdescription = T.pack "Budget transaction" }
 | 
				
			||||||
 | 
				
			|||||||
@ -341,6 +341,7 @@ Balance changes in 2017/11/01-2017/12/31:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Note --budget first arrived in hledger in 1.5 and is still pretty young; 
 | 
					Note --budget first arrived in hledger in 1.5 and is still pretty young; 
 | 
				
			||||||
join the discussions on mail list and issue tracker to help us refine it.  
 | 
					join the discussions on mail list and issue tracker to help us refine it.  
 | 
				
			||||||
 | 
					Also, the `-S/--sort-amount` flag is not yet supported with --budget.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
For more examples, see [Budgeting and Forecasting](https://github.com/simonmichael/hledger/wiki/Budgeting and forecasting).
 | 
					For more examples, see [Budgeting and Forecasting](https://github.com/simonmichael/hledger/wiki/Budgeting and forecasting).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -125,8 +125,7 @@ Budget performance in 2016/12/01-2016/12/03:
 | 
				
			|||||||
  (b)  1
 | 
					  (b)  1
 | 
				
			||||||
  (c)  1
 | 
					  (c)  1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 4. --budget uses only periodic transactions of the specified interval.
 | 
					# 4. --budget with no interval has no effect.
 | 
				
			||||||
# No interval - same as a regular balance report.
 | 
					 | 
				
			||||||
$ hledger -f- bal --budget
 | 
					$ hledger -f- bal --budget
 | 
				
			||||||
                   2  a
 | 
					                   2  a
 | 
				
			||||||
                   2  b
 | 
					                   2  b
 | 
				
			||||||
@ -134,31 +133,31 @@ $ hledger -f- bal --budget
 | 
				
			|||||||
--------------------
 | 
					--------------------
 | 
				
			||||||
                   6
 | 
					                   6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 5. With -D it selects the daily budget. 
 | 
					# 5. Multiple periodic transactions with different intervals are combined. 
 | 
				
			||||||
# The budget is unbounded, so extends through the report period.
 | 
					# Budget goals with lower frequency than the report are posted in the 
 | 
				
			||||||
 | 
					# appropriate intermittent periods. 
 | 
				
			||||||
$ hledger -f- bal --budget -D
 | 
					$ hledger -f- bal --budget -D
 | 
				
			||||||
Budget performance in 2018/01/01-2018/01/03:
 | 
					Budget performance in 2018/01/01-2018/01/03:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   ||               2018/01/01                2018/01/02                2018/01/03 
 | 
					   ||               2018/01/01                2018/01/02                2018/01/03 
 | 
				
			||||||
===++==============================================================================
 | 
					===++==============================================================================
 | 
				
			||||||
 a ||       1 [  10% of    10]        0 [   0% of    10]        1 [  10% of    10] 
 | 
					 a ||       1 [  10% of    10]        0 [   0% of    10]        1 [  10% of    10] 
 | 
				
			||||||
 b ||       1                         0                         1                  
 | 
					 b ||       1 [   1% of   100]        0 [   0% of     0]        1 [             0] 
 | 
				
			||||||
 c ||       1                         0                         1                  
 | 
					 c ||       1 [   0% of  1000]        0 [   0% of     0]        1 [             0] 
 | 
				
			||||||
---++------------------------------------------------------------------------------
 | 
					---++------------------------------------------------------------------------------
 | 
				
			||||||
   ||       3 [  30% of    10]        0 [   0% of    10]        3 [  30% of    10] 
 | 
					   ||       3 [   0% of  1110]        0 [   0% of    10]        3 [  30% of    10] 
 | 
				
			||||||
# TODO misleading totals ? ^
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 6. And with -W it selects the weekly budget, defined by all weekly periodic transactions.
 | 
					# 6. Budget goals with higher frequency than the report get added up appropriately.
 | 
				
			||||||
$ hledger -f- bal --budget -W
 | 
					$ hledger -f- bal --budget -W
 | 
				
			||||||
Budget performance in 2018/01/01w01:
 | 
					Budget performance in 2018/01/01w01:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   ||            2018/01/01w01 
 | 
					   ||            2018/01/01w01 
 | 
				
			||||||
===++==========================
 | 
					===++==========================
 | 
				
			||||||
 a ||       2                  
 | 
					 a ||       2 [   7% of    30] 
 | 
				
			||||||
 b ||       2 [   2% of   100] 
 | 
					 b ||       2 [   2% of   100] 
 | 
				
			||||||
 c ||       2 [   0% of  1000] 
 | 
					 c ||       2 [   0% of  1000] 
 | 
				
			||||||
---++--------------------------
 | 
					---++--------------------------
 | 
				
			||||||
   ||       6 [   1% of  1100] 
 | 
					   ||       6 [   1% of  1130] 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# 7. A bounded two day budget. The end date is exclusive as usual.
 | 
					# 7. A bounded two day budget. The end date is exclusive as usual.
 | 
				
			||||||
<
 | 
					<
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user