@@ -22,6 +22,7 @@ import Hledger.Cli.CliOptions
22
22
import Safe (lastDef , readMay , readDef )
23
23
import System.FilePath (takeFileName )
24
24
import Data.Char (isDigit )
25
+ import Hledger.Read.RulesReader (parseBalanceAssertionType )
25
26
26
27
defclosedesc = " closing balances"
27
28
defopendesc = " opening balances"
@@ -44,6 +45,7 @@ closemode = hledgerCommandMode
44
45
,flagNone [" explicit" ," x" ] (setboolopt " explicit" ) " show all amounts explicitly"
45
46
,flagNone [" show-costs" ] (setboolopt " show-costs" ) " show amounts with different costs separately"
46
47
,flagNone [" interleaved" ] (setboolopt " interleaved" ) " show source and destination postings together"
48
+ ,flagReq [" assertion-type" ] (\ s opts -> Right $ setopt " assertion-type" s opts) " TYPE" " =, ==, =* or ==*"
47
49
,flagReq [" close-desc" ] (\ s opts -> Right $ setopt " close-desc" s opts) " DESC" " set closing transaction's description"
48
50
,flagReq [" close-acct" ] (\ s opts -> Right $ setopt " close-acct" s opts) " ACCT" " set closing transaction's destination account"
49
51
,flagReq [" open-desc" ] (\ s opts -> Right $ setopt " open-desc" s opts) " DESC" " set opening transaction's description"
@@ -135,6 +137,12 @@ close copts@CliOpts{rawopts_=rawopts, reportspec_=rspec0} j = do
135
137
-- interleave equity postings next to the corresponding closing posting, or put them all at the end ?
136
138
interleaved = boolopt " interleaved" rawopts
137
139
140
+ -- a balance assertion template of the right type
141
+ assertion =
142
+ case maybestringopt " assertion-type" rawopts >>= parseBalanceAssertionType of
143
+ Nothing -> nullassertion
144
+ Just (total, inclusive) -> nullassertion{batotal= total, bainclusive= inclusive}
145
+
138
146
-- the closing (balance-asserting or balance-zeroing) transaction
139
147
mclosetxn
140
148
| mode_ `notElem` [Migrate , Close , Assert , Retain ] = Nothing
@@ -158,7 +166,7 @@ close copts@CliOpts{rawopts_=rawopts, reportspec_=rspec0} j = do
158
166
-- balance assertion amounts are unpriced (#824)
159
167
,pbalanceassertion =
160
168
if islast
161
- then Just nullassertion {baamount= precise b}
169
+ then Just assertion {baamount= precise b}
162
170
else Nothing
163
171
}
164
172
| -- get the balances for each commodity and transaction price
@@ -178,7 +186,7 @@ close copts@CliOpts{rawopts_=rawopts, reportspec_=rspec0} j = do
178
186
-- balance assertion amounts are unpriced (#824)
179
187
,pbalanceassertion =
180
188
if islast
181
- then Just nullassertion {baamount= precise b{aquantity= 0 , acost= Nothing }}
189
+ then Just assertion {baamount= precise b{aquantity= 0 , acost= Nothing }}
182
190
else Nothing
183
191
}
184
192
@@ -210,7 +218,7 @@ close copts@CliOpts{rawopts_=rawopts, reportspec_=rspec0} j = do
210
218
| mode_ == Assign =
211
219
[ posting{paccount = a
212
220
,pamount = missingmixedamt
213
- ,pbalanceassertion = Just nullassertion {baamount= b}
221
+ ,pbalanceassertion = Just assertion {baamount= b}
214
222
-- case mcommoditysum of
215
223
-- Just s -> Just nullassertion{baamount=precise s}
216
224
-- Nothing -> Nothing
@@ -232,7 +240,7 @@ close copts@CliOpts{rawopts_=rawopts, reportspec_=rspec0} j = do
232
240
,pamount = mixedAmount $ precise b
233
241
,pbalanceassertion =
234
242
case mcommoditysum of
235
- Just s -> Just nullassertion {baamount= precise s{acost= Nothing }}
243
+ Just s -> Just assertion {baamount= precise s{acost= Nothing }}
236
244
Nothing -> Nothing
237
245
}
238
246
: [posting{paccount= openacct, pamount= mixedAmount . precise $ negate b} | interleaved]
0 commit comments