diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index b41eea365..fa70d75f8 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -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}) diff --git a/hledger/test/check-commodities.test b/hledger/test/check-commodities.test index b20b8154c..51a22ec4c 100644 --- a/hledger/test/check-commodities.test +++ b/hledger/test/check-commodities.test @@ -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