lib: auto postings are generated right after posting that triggered them (#729)
This commit is contained in:
parent
ecf49b1e4b
commit
93814652f8
@ -71,8 +71,9 @@ runModifierTransaction :: Query -> ModifierTransaction -> (Transaction -> Transa
|
||||
runModifierTransaction q mt = modifier where
|
||||
q' = simplifyQuery $ And [q, mtvaluequery mt (error "query cannot depend on current time")]
|
||||
mods = map runModifierPosting $ mtpostings mt
|
||||
generatePostings ps = [m p | p <- ps, q' `matchesPosting` p, m <- mods]
|
||||
modifier t@(tpostings -> ps) = t { tpostings = ps ++ generatePostings ps }
|
||||
generatePostings ps = [p' | p <- ps
|
||||
, p' <- if q' `matchesPosting` p then p:[ m p | m <- mods] else [p]]
|
||||
modifier t@(tpostings -> ps) = t { tpostings = generatePostings ps }
|
||||
|
||||
-- | Extract 'Query' equivalent of 'mtvalueexpr' from 'ModifierTransaction'
|
||||
--
|
||||
|
||||
@ -15,10 +15,10 @@ hledger print -f- --auto
|
||||
>>>
|
||||
2016/01/01 paycheck
|
||||
income:remuneration $-100
|
||||
income:donations $-15
|
||||
assets:bank
|
||||
(liabilities:tax) $-33 ; income tax
|
||||
income:donations $-15
|
||||
(liabilities:tax) $-5 ; income tax
|
||||
assets:bank
|
||||
|
||||
2016/01/01 withdraw
|
||||
assets:cash $20
|
||||
@ -42,15 +42,30 @@ hledger register -f- --auto
|
||||
(liabilities:tax) *.33 ; income tax
|
||||
>>>
|
||||
2016/01/01 paycheck income:remuneration $-100 $-100
|
||||
income:donations $-15 $-115
|
||||
assets:bank $115 0
|
||||
(liabilities:tax) $-33 $-33
|
||||
(liabilities:tax) $-5 $-38
|
||||
(liabilities:tax) $-33 $-133
|
||||
income:donations $-15 $-148
|
||||
(liabilities:tax) $-5 $-153
|
||||
assets:bank $115 $-38
|
||||
2016/01/01 withdraw assets:cash $20 $-18
|
||||
assets:bank $-20 $-38
|
||||
>>>2
|
||||
>>>=0
|
||||
|
||||
hledger register -f- --auto
|
||||
<<<
|
||||
= trigger
|
||||
(target) 10
|
||||
|
||||
2018/1/1
|
||||
(trigger) 1
|
||||
(target) 1 = 11 ; this assertion would not fail, auto posting will be taken into account
|
||||
>>>
|
||||
2018/01/01 (trigger) 1 1
|
||||
(target) 10 11
|
||||
(target) 1 12
|
||||
>>>2
|
||||
>>>=0
|
||||
|
||||
hledger balance -f- --auto
|
||||
<<<
|
||||
2016/1/1 paycheck
|
||||
|
||||
@ -14,10 +14,10 @@ hledger rewrite -f- ^income --add-posting '(liabilities:tax) *.33 ; income tax
|
||||
>>>
|
||||
2016/01/01 paycheck
|
||||
income:remuneration $-100
|
||||
income:donations $-15
|
||||
assets:bank
|
||||
(liabilities:tax) $-33 ; income tax
|
||||
income:donations $-15
|
||||
(liabilities:tax) $-5 ; income tax
|
||||
assets:bank
|
||||
|
||||
2016/01/01 withdraw
|
||||
assets:cash $20
|
||||
@ -194,25 +194,25 @@ hledger rewrite -f- date:2017/1 --add-posting 'Here comes Santa $0'
|
||||
|
||||
2017/01/01
|
||||
expenses:food $20.00
|
||||
(budget:food) $-20.00
|
||||
Here comes Santa 0
|
||||
expenses:leisure $15.00
|
||||
(budget:misc) $-15.00
|
||||
Here comes Santa 0
|
||||
expenses:grocery $30.00
|
||||
(budget:food) $-30.00
|
||||
Here comes Santa 0
|
||||
assets:cash
|
||||
Here comes Santa 0
|
||||
Here comes Santa 0
|
||||
Here comes Santa 0
|
||||
Here comes Santa 0
|
||||
(budget:food) $-20.00
|
||||
(budget:food) $-30.00
|
||||
(budget:misc) $-15.00
|
||||
|
||||
2017/01/02
|
||||
assets:cash $200.00
|
||||
Here comes Santa 0
|
||||
assets:bank
|
||||
Here comes Santa 0
|
||||
Here comes Santa 0
|
||||
assets:bank $-1.60
|
||||
expenses:fee $1.60 ; cash withdraw fee
|
||||
(budget:misc) $-1.60
|
||||
Here comes Santa 0
|
||||
|
||||
2017/02/01
|
||||
assets:cash $100.00
|
||||
|
||||
Loading…
Reference in New Issue
Block a user