diff --git a/hledger/Hledger/Cli/Commands/Import.hs b/hledger/Hledger/Cli/Commands/Import.hs index 9598b3725..b5142a0ec 100755 --- a/hledger/Hledger/Cli/Commands/Import.hs +++ b/hledger/Hledger/Cli/Commands/Import.hs @@ -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 diff --git a/hledger/Hledger/Cli/Commands/Import.md b/hledger/Hledger/Cli/Commands/Import.md index 56572405d..4a8efe762 100644 --- a/hledger/Hledger/Cli/Commands/Import.md +++ b/hledger/Hledger/Cli/Commands/Import.md @@ -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. \ No newline at end of file diff --git a/tests/import/a.csv b/tests/import/a.csv new file mode 100644 index 000000000..78e55fdc6 --- /dev/null +++ b/tests/import/a.csv @@ -0,0 +1 @@ +2020-01-01,"1.000.000,00" diff --git a/tests/import/a.csv.rules b/tests/import/a.csv.rules new file mode 100644 index 000000000..12f56b793 --- /dev/null +++ b/tests/import/a.csv.rules @@ -0,0 +1,2 @@ +fields date,amount +decimal-mark , diff --git a/tests/import/a.j b/tests/import/a.j new file mode 100644 index 000000000..6edef3754 --- /dev/null +++ b/tests/import/a.j @@ -0,0 +1,2 @@ +2020-01-01 + (a) €1.00 diff --git a/tests/import/import.test b/tests/import/import.test new file mode 100644 index 000000000..ee4e68d43 --- /dev/null +++ b/tests/import/import.test @@ -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 + +>=