fix:add: apply the D default commodity to bare numbers, per docs [#815]

This commit is contained in:
Simon Michael 2024-01-04 13:24:57 -10:00
parent 9f5f235198
commit 1fcc8f1c89
3 changed files with 20 additions and 7 deletions

View File

@ -348,10 +348,9 @@ amountAndCommentWizard PrevInput{..} EntryState{..} = do
where
parseAmountAndComment s = if s == "<" then return Nothing else either (const Nothing) (return . Just) $
runParser
(evalStateT (amountandcommentp <* eof) nodefcommodityj)
(evalStateT (amountandcommentp <* eof) esJournal)
""
(T.pack s)
nodefcommodityj = esJournal{jparsedefaultcommodity=Nothing}
amountandcommentp :: JournalParser Identity (Amount, Text)
amountandcommentp = do
a <- amountp

View File

@ -26,7 +26,7 @@ Features:
- The tab key will auto-complete whenever possible - accounts,
payees/descriptions, dates (`yesterday`, `today`, `tomorrow`).
If the input area is empty, it will insert the default value.
- If the journal defines a [default commodity](#default-commodity),
- If the journal defines a [default commodity](#d-directive),
it will be added to any bare numbers entered.
- A parenthesised transaction [code](#entries) may be entered following a date.
- [Comments](#transaction-comments) and tags may be entered following a description or amount.

View File

@ -60,7 +60,21 @@ $$$ printf 'D $1000.0\n' >t$$.j; hledger -f t$$.j add >/dev/null; cat t$$.j; rm
>>> /a +\$1000\.00/
>>>2 //
# ** 6. existing commodity with greater precision
# ** 6. default commodity symbol is added when not entered
<<<
a
1000
b
.
$$$ printf 'D $1000.00\n' >t$$.j; hledger -f t$$.j add >/dev/null; cat t$$.j; rm -f t$$.j
>>> /a +\$1000\.00/
>>>2 //
# ** 7. existing commodity with greater precision
<<<
@ -73,7 +87,7 @@ $$$ printf '2010/1/1\n a $1000.00\n b\n' >t$$.j; hledger -f t$$.j add >/dev/nu
>>> /a +\$1000\.0/
>>>2 //
# ** 7. existing commodity with less precision
# ** 8. existing commodity with less precision
<<<
@ -87,7 +101,7 @@ $$$ printf '2010/1/1\n a $1000.0\n b\n' >t$$.j; hledger -f t$$.j add >/dev/nul
>>> /a +\$1000\.00/
>>>2 //
# ** 8. default amounts should not fail to balance due to precision
# ** 9. default amounts should not fail to balance due to precision
<<<
2010/1/1
x
@ -100,7 +114,7 @@ $$$ rm -f nosuch.journal; hledger -f nosuch.journal add; rm -f nosuch.journal
>>> /Amount 3 \[-0.75\]:/
>>>2 //
## 9. shouldn't add decimals if there aren't any
## 10. shouldn't add decimals if there aren't any
## printf '\n\na\n1\nb\n' | hledger -f /dev/null add
# hledger -f /dev/null add
# <<<