csv, journal: infer style from first amount, as documented, not last

This has been broken since hledger 1.12 (!)
This commit is contained in:
Simon Michael 2020-11-10 08:40:08 -08:00
parent f43c7e41d1
commit 8bdb28a991
2 changed files with 27 additions and 12 deletions

View File

@ -312,21 +312,19 @@ journalFinalise :: InputOpts -> FilePath -> Text -> ParsedJournal -> ExceptT Str
journalFinalise InputOpts{auto_,ignore_assertions_,commoditystyles_} f txt pj = do journalFinalise InputOpts{auto_,ignore_assertions_,commoditystyles_} f txt pj = do
t <- liftIO getClockTime t <- liftIO getClockTime
d <- liftIO getCurrentDay d <- liftIO getCurrentDay
-- Set any global commodity styles that have been provided via InputOpts let pj' =
let pj' = pj{jglobalcommoditystyles=fromMaybe M.empty commoditystyles_} pj{jglobalcommoditystyles=fromMaybe M.empty commoditystyles_} -- save any global commodity styles
& journalAddFile (f, txt) -- save the main file's info
& journalSetLastReadTime t -- save the last read time
& journalReverse -- convert all lists to the order they were parsed
-- Infer and apply canonical styles for each commodity (or throw an error). -- Infer and apply canonical styles for each commodity (or throw an error).
-- This affects transaction balancing/assertions/assignments, so needs to be done early. -- This affects transaction balancing/assertions/assignments, so needs to be done early.
-- (TODO: since #903's refactoring for hledger 1.12,
-- journalApplyCommodityStyles here is seeing the
-- transactions before they get reversesd to normal order.)
case journalApplyCommodityStyles pj' of case journalApplyCommodityStyles pj' of
Left e -> throwError e Left e -> throwError e
Right pj' -> either throwError return $ Right pj'' -> either throwError return $
pj' pj''
& journalAddFile (f, txt) -- save the file path and content & (if not auto_ || null (jtxnmodifiers pj')
& journalSetLastReadTime t -- save the last read time
& journalReverse -- convert all lists to parse order
& (if not auto_ || null (jtxnmodifiers pj)
then then
-- Auto postings are not active. -- Auto postings are not active.
-- Balance all transactions and maybe check balance assertions. -- Balance all transactions and maybe check balance assertions.

View File

@ -178,3 +178,20 @@ $ hledger -f- bal a
# 2000-01-01 # 2000-01-01
# a $-10,000 # a $-10,000
# b $10,000,000 # b $10,000,000
# 13. A commodity's display style should come from the first-parsed amount
<
2020-01-01
(a) 1.00 $
2020-01-02
(b) $2,00
$ hledger -f - print
2020-01-01
(a) 1.00 $
2020-01-02
(b) 2.00 $
>=