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) (linesPrepend " " . (<>"\n") . textChomp $ showTransaction t)
where where
mfirstundeclaredcomm = mfirstundeclaredcomm =
find (`M.notMember` jcommodities j) . map acommodity $ find (`M.notMember` jcommodities j)
(maybe id ((:) . baamount) pbalanceassertion) . filter (/= missingamt) $ amountsRaw pamount . 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 :: Year -> JournalParser m ()
setYear y = modify' (\j -> j{jparsedefaultyear=Just y}) 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. commodity $1.
2020-01-01 2020-01-01
(a) $1 (a) $1
$ hledger -f- check commodities $ hledger -f- check commodities
# and otherwise fails # 2. and otherwise fails
< <
2020-01-01 2020-01-01
(a) $1 (a) $1
$ hledger -f- check commodities $ hledger -f- check commodities
>2 /undeclared commodity "\$"/ >2 /undeclared commodity "\$"/
>=1 >=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