import: apply journal's commodity styles to imported amounts

This commit is contained in:
Simon Michael 2020-11-09 16:09:43 -08:00
parent 687494834b
commit 78894d46c8
6 changed files with 20 additions and 1 deletions

View File

@ -32,7 +32,7 @@ importcmd opts@CliOpts{rawopts_=rawopts,inputopts_=iopts} j = do
inputstr = intercalate ", " $ map quoteIfNeeded inputfiles
catchup = boolopt "catchup" rawopts
dryrun = boolopt "dry-run" rawopts
iopts' = iopts{new_=True, new_save_=not dryrun}
iopts' = iopts{new_=True, new_save_=not dryrun, commoditystyles_=Just $ journalCommodityStyles j}
case inputfiles of
[] -> error' "please provide one or more input files as arguments" -- PARTIAL:
fs -> do

View File

@ -37,3 +37,8 @@ $ hledger print IMPORTFILE [--new] >> $LEDGER_FILE
(If you think import should leave amounts implicit like print does,
please test it and send a pull request.)
### Commodity display styles
Imported amounts will be formatted according to the canonical [commodity styles](journal.html#commodity-display-style)
(declared or inferred) in the main journal file.

1
tests/import/a.csv Normal file
View File

@ -0,0 +1 @@
2020-01-01,"1.000.000,00"
1 2020-01-01 1.000.000,00

2
tests/import/a.csv.rules Normal file
View File

@ -0,0 +1,2 @@
fields date,amount
decimal-mark ,

2
tests/import/a.j Normal file
View File

@ -0,0 +1,2 @@
2020-01-01
(a) €1.00

9
tests/import/import.test Normal file
View File

@ -0,0 +1,9 @@
# import applies the receiving journal's commodity styles to imported amounts
$ hledger -f a.j import --dry-run a.csv
; would import 1 new transactions from a.csv:
2020-01-01
expenses:unknown 1.000.000,00
income:unknown -1.000.000,00
>=