imp: check: Do not check commodities for zero amounts with empty

commodity. (#1767)
This commit is contained in:
Stephen Morgan 2021-12-04 23:40:40 +11:00 committed by Simon Michael
parent dbcd235f9e
commit 5006e26995
2 changed files with 26 additions and 4 deletions

View File

@ -403,9 +403,14 @@ journalCheckCommoditiesDeclared j =
(linesPrepend " " . (<>"\n") . textChomp $ showTransaction t)
where
mfirstundeclaredcomm =
find (`M.notMember` jcommodities j) . map acommodity $
(maybe id ((:) . baamount) pbalanceassertion) . filter (/= missingamt) $ amountsRaw pamount
find (`M.notMember` jcommodities j)
. map acommodity
. (maybe id ((:) . baamount) pbalanceassertion)
. filter (not . isIgnorable)
$ amountsRaw pamount
-- Ignore missing amounts and zero amounts without commodity (#1767)
isIgnorable a = (T.null (acommodity a) && amountIsZero a) || a == missingamt
setYear :: Year -> JournalParser m ()
setYear y = modify' (\j -> j{jparsedefaultyear=Just y})

View File

@ -1,14 +1,31 @@
# check commodities succeeds when all commodities are declared
# 1. check commodities succeeds when all commodities are declared
<
commodity $1.
2020-01-01
(a) $1
$ hledger -f- check commodities
# and otherwise fails
# 2. and otherwise fails
<
2020-01-01
(a) $1
$ hledger -f- check commodities
>2 /undeclared commodity "\$"/
>=1
# 3. But commodityless zero amounts will not fail
<
2020-01-01
(a) 0
$ hledger -f- check commodities
>=0
# 4. But zero amounts with undeclared commodities still fail
<
2020-01-01
(a) $0
$ hledger -f- check commodities
>2 /undeclared commodity "\$"/
>=1