fix:print: pad/round amounts with inferred costs like the others (#2123)

This commit is contained in:
Simon Michael 2023-12-07 03:37:19 -10:00
parent cf48fbfad8
commit 22ac8d056d

View File

@ -113,22 +113,15 @@ printEntries opts@CliOpts{rawopts_=rawopts, reportspec_=rspec} j =
where styles0 = journalCommodityStyles j where styles0 = journalCommodityStyles j
fmt = outputFormatFromOpts opts fmt = outputFormatFromOpts opts
render | fmt=="txt" = entriesReportAsText opts . styleAmounts styles render | fmt=="txt" = entriesReportAsText . styleAmounts styles . map maybeoriginalamounts
| fmt=="beancount" = entriesReportAsBeancount opts . styleAmounts styles | fmt=="beancount" = entriesReportAsBeancount . styleAmounts styles . map maybeoriginalamounts
| fmt=="csv" = printCSV . entriesReportAsCsv . styleAmounts styles | fmt=="csv" = printCSV . entriesReportAsCsv . styleAmounts styles
| fmt=="tsv" = printTSV . entriesReportAsCsv . styleAmounts styles | fmt=="tsv" = printTSV . entriesReportAsCsv . styleAmounts styles
| fmt=="json" = toJsonText . styleAmounts styles | fmt=="json" = toJsonText . styleAmounts styles
| fmt=="sql" = entriesReportAsSql . styleAmounts styles | fmt=="sql" = entriesReportAsSql . styleAmounts styles
| otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL: | otherwise = error' $ unsupportedOutputFormatError fmt -- PARTIAL:
entriesReportAsText :: CliOpts -> EntriesReport -> TL.Text
entriesReportAsText = entriesReportAsTextHelper showTransaction
entriesReportAsTextHelper :: (Transaction -> T.Text) -> CliOpts -> EntriesReport -> TL.Text
entriesReportAsTextHelper showtxn opts =
TB.toLazyText . foldMap (TB.fromText . showtxn . txntransform)
where where
txntransform maybeoriginalamounts
-- Use the fully inferred and amount-styled/rounded transaction in the following situations: -- Use the fully inferred and amount-styled/rounded transaction in the following situations:
-- with -x/--explicit: -- with -x/--explicit:
| boolopt "explicit" (rawopts_ opts) = id | boolopt "explicit" (rawopts_ opts) = id
@ -144,24 +137,28 @@ entriesReportAsTextHelper showtxn opts =
-- This is mainly for showing transactions with the amounts in their original journal format. -- This is mainly for showing transactions with the amounts in their original journal format.
transactionWithMostlyOriginalPostings :: Transaction -> Transaction transactionWithMostlyOriginalPostings :: Transaction -> Transaction
transactionWithMostlyOriginalPostings = transactionMapPostings postingMostlyOriginal transactionWithMostlyOriginalPostings = transactionMapPostings postingMostlyOriginal
where
-- Get the original posting if any, but keep the current (possibly rewritten) account name, postingMostlyOriginal p = orig
-- and the amounts of any auto postings.
postingMostlyOriginal p = orig
{ paccount = paccount p { paccount = paccount p
, pamount = pamount $ if isGenerated then p else orig } , pamount = pamount $ if isGenerated then p else orig }
where where
orig = originalPosting p orig = originalPosting p
isGenerated = "_generated-posting" `elem` map fst (ptags p) isGenerated = "_generated-posting" `elem` map fst (ptags p)
entriesReportAsText :: EntriesReport -> TL.Text
entriesReportAsText = entriesReportAsTextHelper showTransaction
entriesReportAsTextHelper :: (Transaction -> T.Text) -> EntriesReport -> TL.Text
entriesReportAsTextHelper showtxn = TB.toLazyText . foldMap (TB.fromText . showtxn)
-- In addition to rendering the transactions in (best effort) Beancount format, -- In addition to rendering the transactions in (best effort) Beancount format,
-- this generates an account open directive for each account name used -- this generates an account open directive for each account name used
-- (using the earliest transaction date). -- (using the earliest transaction date).
entriesReportAsBeancount :: CliOpts -> EntriesReport -> TL.Text entriesReportAsBeancount :: EntriesReport -> TL.Text
entriesReportAsBeancount opts ts = entriesReportAsBeancount ts =
-- PERF: gathers and converts all account names, then repeats that work when showing each transaction -- PERF: gathers and converts all account names, then repeats that work when showing each transaction
opendirectives <> "\n" <> opendirectives <> "\n" <>
entriesReportAsTextHelper showTransactionBeancount opts ts entriesReportAsTextHelper showTransactionBeancount ts
where where
opendirectives opendirectives
| null ts = "" | null ts = ""