mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-26 03:42:25 +03:00
close: use exact, minimal amounts; ensure assertions pass (#941)
This commit is contained in:
parent
9e4b302af7
commit
7b47fb608e
@ -34,8 +34,11 @@ This command may also be useful for closing out expense/income accounts
|
|||||||
for a period (ie "closing the books" in accounting).
|
for a period (ie "closing the books" in accounting).
|
||||||
|
|
||||||
Both transactions include balance assertions for the closed/reopened accounts.
|
Both transactions include balance assertions for the closed/reopened accounts.
|
||||||
|
|
||||||
You probably shouldn't use status or realness queries (eg -C or -R) with this
|
You probably shouldn't use status or realness queries (eg -C or -R) with this
|
||||||
command, or the balance assertions will require that query to pass.
|
command, or the balance assertions will require that query to pass.
|
||||||
|
Likewise, if you generate them with --auto, the assertions will depend on
|
||||||
|
any auto postings and --auto will be required to make them pass.
|
||||||
|
|
||||||
By default, the closing transaction is dated yesterday, with balances
|
By default, the closing transaction is dated yesterday, with balances
|
||||||
calculated as of end of yesterday, and the opening transaction is dated today.
|
calculated as of end of yesterday, and the opening transaction is dated today.
|
||||||
@ -83,17 +86,22 @@ close CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do
|
|||||||
closingdate = addDays (-1) openingdate
|
closingdate = addDays (-1) openingdate
|
||||||
(acctbals,_) = balanceReportFromMultiBalanceReport ropts_ q j
|
(acctbals,_) = balanceReportFromMultiBalanceReport ropts_ q j
|
||||||
balancingamt = negate $ sum $ map (\(_,_,_,b) -> normaliseMixedAmountSquashPricesForDisplay b) acctbals
|
balancingamt = negate $ sum $ map (\(_,_,_,b) -> normaliseMixedAmountSquashPricesForDisplay b) acctbals
|
||||||
|
|
||||||
|
-- since balance assertion amounts are required to be exact, the
|
||||||
|
-- amounts in opening/closing transactions should be too (#941)
|
||||||
|
-- setprec = setFullPrecision
|
||||||
|
setprec = setMinimalPrecision
|
||||||
ps = [posting{paccount=a
|
ps = [posting{paccount=a
|
||||||
,pamount=mixed [b]
|
,pamount=mixed [setprec b]
|
||||||
,pbalanceassertion=Just assertion{ baamount=b }
|
,pbalanceassertion=Just assertion{ baamount=setprec b }
|
||||||
}
|
}
|
||||||
|(a,_,_,mb) <- acctbals
|
|(a,_,_,mb) <- acctbals
|
||||||
,b <- amounts $ normaliseMixedAmountSquashPricesForDisplay mb
|
,b <- amounts $ normaliseMixedAmountSquashPricesForDisplay mb
|
||||||
]
|
]
|
||||||
++ [posting{paccount="equity:opening balances", pamount=balancingamt}]
|
++ [posting{paccount="equity:opening balances", pamount=balancingamt}]
|
||||||
nps = [posting{paccount=a
|
nps = [posting{paccount=a
|
||||||
,pamount=mixed [negate b]
|
,pamount=mixed [setprec $ negate b]
|
||||||
,pbalanceassertion=Just assertion{ baamount=b{aquantity=0} }
|
,pbalanceassertion=Just assertion{ baamount= setprec b{aquantity=0} }
|
||||||
}
|
}
|
||||||
|(a,_,_,mb) <- acctbals
|
|(a,_,_,mb) <- acctbals
|
||||||
,b <- amounts $ normaliseMixedAmountSquashPricesForDisplay mb
|
,b <- amounts $ normaliseMixedAmountSquashPricesForDisplay mb
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
# Simple case
|
# 1. Simple case
|
||||||
hledger close -f- -p 2016 assets liabilities
|
hledger close -f- -p 2016 assets liabilities
|
||||||
<<<
|
<<<
|
||||||
2016/1/1 open
|
2016/1/1 open
|
||||||
@ -33,7 +33,7 @@ hledger close -f- -p 2016 assets liabilities
|
|||||||
|
|
||||||
>>>=0
|
>>>=0
|
||||||
|
|
||||||
# Test aggregation of postings with prices
|
# 2. Test aggregation of postings with prices
|
||||||
hledger close -f- -p 2016 assets liabilities
|
hledger close -f- -p 2016 assets liabilities
|
||||||
<<<
|
<<<
|
||||||
Y2016
|
Y2016
|
||||||
@ -58,18 +58,18 @@ Y2016
|
|||||||
liabilities:employer
|
liabilities:employer
|
||||||
>>>
|
>>>
|
||||||
2016/12/31 closing balances
|
2016/12/31 closing balances
|
||||||
assets:bank -5,733.00 EUR = 0.00 EUR
|
assets:bank -5,733 EUR = 0 EUR
|
||||||
liabilities:employer -1.00 EUR = 0.00 EUR
|
liabilities:employer -1 EUR = 0 EUR
|
||||||
equity:closing balances
|
equity:closing balances
|
||||||
|
|
||||||
2017/01/01 opening balances
|
2017/01/01 opening balances
|
||||||
assets:bank 5,733.00 EUR = 5,733.00 EUR
|
assets:bank 5,733 EUR = 5,733 EUR
|
||||||
liabilities:employer 1.00 EUR = 1.00 EUR
|
liabilities:employer 1 EUR = 1 EUR
|
||||||
equity:opening balances
|
equity:opening balances
|
||||||
|
|
||||||
>>>=0
|
>>>=0
|
||||||
|
|
||||||
# A begin date should be ignored
|
# 3. A begin date should be ignored
|
||||||
hledger close -f- -b2017/6/1 -e2018
|
hledger close -f- -b2017/6/1 -e2018
|
||||||
<<<
|
<<<
|
||||||
2017/1/1
|
2017/1/1
|
||||||
@ -85,7 +85,7 @@ hledger close -f- -b2017/6/1 -e2018
|
|||||||
|
|
||||||
>>>=0
|
>>>=0
|
||||||
|
|
||||||
# Print just the opening transaction
|
# 4. Print just the opening transaction
|
||||||
hledger close -f- -p 2016 assets liabilities --opening
|
hledger close -f- -p 2016 assets liabilities --opening
|
||||||
<<<
|
<<<
|
||||||
2016/1/1 open
|
2016/1/1 open
|
||||||
@ -113,7 +113,7 @@ hledger close -f- -p 2016 assets liabilities --opening
|
|||||||
|
|
||||||
>>>=0
|
>>>=0
|
||||||
|
|
||||||
# Print just the closing transaction
|
# 5. Print just the closing transaction
|
||||||
hledger close -f- -p 2016 assets liabilities --closing
|
hledger close -f- -p 2016 assets liabilities --closing
|
||||||
<<<
|
<<<
|
||||||
2016/1/1 open
|
2016/1/1 open
|
||||||
@ -141,7 +141,7 @@ hledger close -f- -p 2016 assets liabilities --closing
|
|||||||
|
|
||||||
>>>=0
|
>>>=0
|
||||||
|
|
||||||
# Supplying --opening --closing is the same as just "close"
|
# 6. Supplying --opening --closing is the same as just "close"
|
||||||
hledger close -f- -p 2016 assets liabilities --opening --closing
|
hledger close -f- -p 2016 assets liabilities --opening --closing
|
||||||
<<<
|
<<<
|
||||||
2016/1/1 open
|
2016/1/1 open
|
||||||
|
Loading…
Reference in New Issue
Block a user