fix: strict: Make sure forecast transactions and auto postings are
checked with --strict. (#1810)
This commit is contained in:
parent
2cf4c221de
commit
55a022a941
@ -314,14 +314,8 @@ journalFinalise iopts@InputOpts{auto_,infer_equity_,balancingopts_,strict_} f tx
|
|||||||
& journalReverse -- convert all lists to the order they were parsed
|
& journalReverse -- convert all lists to the order they were parsed
|
||||||
where
|
where
|
||||||
checkAddAndBalance d j = do
|
checkAddAndBalance d j = do
|
||||||
when strict_ $ do
|
|
||||||
-- If in strict mode, check all postings are to declared accounts
|
|
||||||
journalCheckAccountsDeclared j
|
|
||||||
-- and using declared commodities
|
|
||||||
journalCheckCommoditiesDeclared j
|
|
||||||
|
|
||||||
-- Add forecast transactions if enabled
|
-- Add forecast transactions if enabled
|
||||||
journalAddForecast (forecastPeriod iopts j) j
|
newj <- journalAddForecast (forecastPeriod iopts j) j
|
||||||
-- Add auto postings if enabled
|
-- Add auto postings if enabled
|
||||||
& (if auto_ && not (null $ jtxnmodifiers j) then journalAddAutoPostings d balancingopts_ else pure)
|
& (if auto_ && not (null $ jtxnmodifiers j) then journalAddAutoPostings d balancingopts_ else pure)
|
||||||
-- Balance all transactions and maybe check balance assertions.
|
-- Balance all transactions and maybe check balance assertions.
|
||||||
@ -331,6 +325,14 @@ journalFinalise iopts@InputOpts{auto_,infer_equity_,balancingopts_,strict_} f tx
|
|||||||
-- infer market prices from commodity-exchanging transactions
|
-- infer market prices from commodity-exchanging transactions
|
||||||
<&> journalInferMarketPricesFromTransactions
|
<&> journalInferMarketPricesFromTransactions
|
||||||
|
|
||||||
|
when strict_ $ do
|
||||||
|
-- If in strict mode, check all postings are to declared accounts
|
||||||
|
journalCheckAccountsDeclared newj
|
||||||
|
-- and using declared commodities
|
||||||
|
journalCheckCommoditiesDeclared newj
|
||||||
|
|
||||||
|
return newj
|
||||||
|
|
||||||
journalAddAutoPostings :: Day -> BalancingOpts -> Journal -> Either String Journal
|
journalAddAutoPostings :: Day -> BalancingOpts -> Journal -> Either String Journal
|
||||||
journalAddAutoPostings d bopts =
|
journalAddAutoPostings d bopts =
|
||||||
-- Balance all transactions without checking balance assertions,
|
-- Balance all transactions without checking balance assertions,
|
||||||
|
|||||||
@ -1,14 +1,49 @@
|
|||||||
# check accounts succeeds when all accounts are declared
|
# 1. check accounts succeeds when all accounts are declared
|
||||||
<
|
<
|
||||||
account a
|
account a
|
||||||
2020-01-01
|
2020-01-01
|
||||||
(a) 1
|
(a) 1
|
||||||
$ hledger -f- check accounts
|
$ hledger -f- check accounts
|
||||||
|
|
||||||
# and otherwise fails:
|
# 2. and otherwise fails:
|
||||||
<
|
<
|
||||||
2020-01-01
|
2020-01-01
|
||||||
(a) 1
|
(a) 1
|
||||||
$ hledger -f- check accounts
|
$ hledger -f- check accounts
|
||||||
>2 /undeclared account "a"/
|
>2 /undeclared account "a"/
|
||||||
>=1
|
>=1
|
||||||
|
|
||||||
|
# 3. also fails for forecast accounts
|
||||||
|
<
|
||||||
|
account a
|
||||||
|
~ 2022-01-31
|
||||||
|
a $1
|
||||||
|
b
|
||||||
|
$ hledger -f- --forecast check accounts
|
||||||
|
>2 /undeclared account "b"/
|
||||||
|
>=1
|
||||||
|
|
||||||
|
# 4. also fails in --strict mode
|
||||||
|
$ hledger -f- --forecast --strict bal
|
||||||
|
>2 /undeclared account "b"/
|
||||||
|
>=1
|
||||||
|
|
||||||
|
# 5. also fails for auto accounts
|
||||||
|
<
|
||||||
|
account a
|
||||||
|
|
||||||
|
= a
|
||||||
|
(b) $1
|
||||||
|
|
||||||
|
2022-01-31
|
||||||
|
(a) $1
|
||||||
|
|
||||||
|
2022-02-01
|
||||||
|
$ hledger -f- --auto check accounts
|
||||||
|
>2 /undeclared account "b"/
|
||||||
|
>=1
|
||||||
|
|
||||||
|
# 6. also fails in --strict mode
|
||||||
|
$ hledger -f- --auto --strict bal
|
||||||
|
>2 /undeclared account "b"/
|
||||||
|
>=1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user