Skip to content
Permalink
Browse files

close: don't strip decimal zeros, causing misparsing (fix #1137)

  • Loading branch information
simonmichael committed Dec 1, 2019
1 parent 279e962 commit 5b6dbe86b39d0eab2d1943981363e34dad9e1de6
Showing with 21 additions and 24 deletions.
  1. +2 −3 hledger/Hledger/Cli/Commands/Close.hs
  2. +19 −21 tests/close.test
@@ -49,9 +49,8 @@ close CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do
balancingamt = negate $ sum $ map (\(_,_,_,b) -> normaliseMixedAmount b) acctbals

-- since balance assertion amounts are required to be exact, the
-- amounts in opening/closing transactions should be too (#941)
-- setprec = setFullPrecision
setprec = setNaturalPrecision
-- amounts in opening/closing transactions should be too (#941, #1137)
setprec = setFullPrecision
-- balance assertion amounts will be unpriced (#824)
-- only the last posting in each commodity will have a balance assertion (#1035)
closingps = [posting{paccount = a
@@ -189,6 +189,8 @@ $ hledger -f- close assets -p 2019
>=0

# 8. Closing a multi-priced balance, a more complex example.
# Decimal places specified by the amount display style should not be stripped
# even if they are zeros (#1137).
<
2016/01/31
liabilities:employer $5,000.00
@@ -210,32 +212,28 @@ $ hledger -f- close assets -p 2019
assets:bank 2,836.00 EUR
liabilities:employer

; Note: without these declarations, the closing/opening entries below
; would cause decimal marks to be misparsed. (How ?)
;commodity $1,000.00
;commodity 1,000.00 EUR

$ hledger -f- close -p 2016 assets liabilities
2016/12/31 closing balances
assets:bank -5,733 EUR = 0 EUR
liabilities:employer $-10,000
liabilities:employer $5,000 @ 0.93 EUR
liabilities:employer $5,000 @ 0.95 EUR = $0
liabilities:employer -1 EUR = 0 EUR
equity:closing balances $10,000.00
assets:bank -5,733.00 EUR = 0.00 EUR
liabilities:employer $-10,000.00
liabilities:employer $5,000.00 @ 0.93 EUR
liabilities:employer $5,000.00 @ 0.95 EUR = $0.00
liabilities:employer -1.00 EUR = 0.00 EUR
equity:closing balances $10,000.00
equity:closing balances $-5,000.00 @ 0.93 EUR
equity:closing balances $-5,000.00 @ 0.95 EUR
equity:closing balances 5,734.00 EUR
equity:closing balances 5,734.00 EUR

2017/01/01 opening balances
assets:bank 5,733 EUR = 5,733 EUR
liabilities:employer $10,000
liabilities:employer $-5,000 @ 0.93 EUR
liabilities:employer $-5,000 @ 0.95 EUR = $0
liabilities:employer 1 EUR = 1 EUR
equity:opening balances $-10,000.00
equity:opening balances $5,000.00 @ 0.93 EUR
equity:opening balances $5,000.00 @ 0.95 EUR
equity:opening balances -5,734.00 EUR
assets:bank 5,733.00 EUR = 5,733.00 EUR
liabilities:employer $10,000.00
liabilities:employer $-5,000.00 @ 0.93 EUR
liabilities:employer $-5,000.00 @ 0.95 EUR = $0.00
liabilities:employer 1.00 EUR = 1.00 EUR
equity:opening balances $-10,000.00
equity:opening balances $5,000.00 @ 0.93 EUR
equity:opening balances $5,000.00 @ 0.95 EUR
equity:opening balances -5,734.00 EUR

>=0

0 comments on commit 5b6dbe8

Please sign in to comment.
You can’t perform that action at this time.