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:
Simon Michael 2018-04-22 10:09:06 -07:00
parent e2c55aafa9
commit 0c140d7238
3 changed files with 16 additions and 18 deletions

View File

@ -73,21 +73,19 @@ budgetReport ropts assrt showunbudgeted reportspan d j =
dbg1 "budgetreport" $
combineBudgetAndActual budgetgoalreport actualreport
-- | Select all periodic transactions from the given journal which
-- match the requested report interval, and use them to generate
-- budget transactions (like forecast transactions) in the specified
-- report period (calculated in IO and passed in).
-- | Use all periodic transactions in the journal to generate
-- budget transactions in the specified report period.
-- Budget transactions are similar to forecast transactions except
-- their purpose is to set goal amounts (of change) per account and period.
budgetJournal :: Bool -> ReportOpts -> DateSpan -> Journal -> Journal
budgetJournal assrt ropts reportspan j =
budgetJournal assrt _ropts reportspan j =
either error' id $ journalBalanceTransactions assrt j{ jtxns = budgetts }
where
budgetinterval = dbg2 "budgetinterval" $ interval_ ropts
budgetspan = dbg2 "budgetspan" $ reportspan
budgetts =
dbg1 "budgetts" $
[makeBudgetTxn t
| pt <- jperiodictxns j
, periodTransactionInterval pt == Just budgetinterval
, t <- runPeriodicTransaction pt budgetspan
]
makeBudgetTxn t = txnTieKnot $ t { tdescription = T.pack "Budget transaction" }

View File

@ -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;
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).

View File

@ -125,8 +125,7 @@ Budget performance in 2016/12/01-2016/12/03:
(b) 1
(c) 1
# 4. --budget uses only periodic transactions of the specified interval.
# No interval - same as a regular balance report.
# 4. --budget with no interval has no effect.
$ hledger -f- bal --budget
2 a
2 b
@ -134,31 +133,31 @@ $ hledger -f- bal --budget
--------------------
6
# 5. With -D it selects the daily budget.
# The budget is unbounded, so extends through the report period.
# 5. Multiple periodic transactions with different intervals are combined.
# Budget goals with lower frequency than the report are posted in the
# appropriate intermittent periods.
$ hledger -f- bal --budget -D
Budget performance in 2018/01/01-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]
b || 1 0 1
c || 1 0 1
b || 1 [ 1% of 100] 0 [ 0% of 0] 1 [ 0]
c || 1 [ 0% of 1000] 0 [ 0% of 0] 1 [ 0]
---++------------------------------------------------------------------------------
|| 3 [ 30% of 10] 0 [ 0% of 10] 3 [ 30% of 10]
# TODO misleading totals ? ^
|| 3 [ 0% of 1110] 0 [ 0% of 10] 3 [ 30% of 10]
# 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
Budget performance in 2018/01/01w01:
|| 2018/01/01w01
===++==========================
a || 2
a || 2 [ 7% of 30]
b || 2 [ 2% of 100]
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.
<