Skip to content

Commit

Permalink
fix:add: rethink adding default commodity symbol; fix doc instead [si…
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichael authored and adept committed Mar 8, 2024
1 parent a3e249b commit 4a6736c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion hledger/Hledger/Cli/Commands/Add.hs
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,10 @@ amountAndCommentWizard PrevInput{..} EntryState{..} = do
where
parseAmountAndComment s = if s == "<" then return Nothing else either (const Nothing) (return . Just) $
runParser
(evalStateT (amountandcommentp <* eof) esJournal)
(evalStateT (amountandcommentp <* eof) nodefcommodityj)
""
(T.pack s)
nodefcommodityj = esJournal{jparsedefaultcommodity=Nothing}
amountandcommentp :: JournalParser Identity (Amount, Text)
amountandcommentp = do
a <- amountp
Expand Down
6 changes: 6 additions & 0 deletions hledger/Hledger/Cli/Commands/Add.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ Starting the next transaction (. or ctrl-D/ctrl-C to quit)
Date [2015/05/22]: <CTRL-D> $
```

If you enter a number with no commodity symbol,
and you have declared a default commodity with a `D` directive,
you might expect `add` to add this symbol for you.
It does not do this; we assume that if you are using a `D` directive
you prefer not to see the commodity symbol repeated on amounts in the journal.

On Microsoft Windows, the add command makes sure that no part of the
file path ends with a period, as that would cause problems
([#1056](https://github.com/simonmichael/hledger/issues/1056)).
4 changes: 2 additions & 2 deletions hledger/test/add.test
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ $ printf 'D A1000.0\n' >t$$.j; hledger -f t$$.j add >/dev/null; cat t$$.j; rm -
> /a +A1000\.00/
>2 //

# ** 6. default commodity symbol is added when not entered
# ** 6. default commodity symbol is not added when not provided (#815)
<


Expand All @@ -71,7 +71,7 @@ b
.

$ printf 'D A1000.00\n' >t$$.j; hledger -f t$$.j add >/dev/null; cat t$$.j; rm -f t$$.j
> /a +A1000\.00/
> /a +1000\.00/
>2 //

# ** 7. existing commodity with greater precision
Expand Down

0 comments on commit 4a6736c

Please sign in to comment.