cln:print: clarify code a bit, rename originalTransaction
This commit is contained in:
parent
79a1f1dd97
commit
f225bf2f7f
@ -11,10 +11,11 @@ module Hledger.Cli.Commands.Print (
|
|||||||
printmode
|
printmode
|
||||||
,print'
|
,print'
|
||||||
-- ,entriesReportAsText
|
-- ,entriesReportAsText
|
||||||
,originalTransaction
|
,transactionWithMostlyOriginalPostings
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
|
|
||||||
import Data.List (intersperse)
|
import Data.List (intersperse)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Lazy as TL
|
import qualified Data.Text.Lazy as TL
|
||||||
@ -79,28 +80,28 @@ printEntries opts@CliOpts{reportspec_=rspec} j =
|
|||||||
|
|
||||||
entriesReportAsText :: CliOpts -> EntriesReport -> TL.Text
|
entriesReportAsText :: CliOpts -> EntriesReport -> TL.Text
|
||||||
entriesReportAsText opts =
|
entriesReportAsText opts =
|
||||||
TB.toLazyText . foldMap (TB.fromText . showTransaction . whichtxn)
|
TB.toLazyText . foldMap (TB.fromText . showTransaction . txntransform)
|
||||||
where
|
where
|
||||||
whichtxn
|
txntransform
|
||||||
-- With -x, use the fully-inferred txn with all amounts & txn prices explicit.
|
-- Use the fully inferred and amount-styled/rounded transaction in the following situations:
|
||||||
|
-- with -x/--explicit:
|
||||||
| boolopt "explicit" (rawopts_ opts) = id
|
| boolopt "explicit" (rawopts_ opts) = id
|
||||||
-- With --show-costs, make txn prices explicit.
|
-- with --show-costs:
|
||||||
| opts ^. infer_costs = id
|
| opts ^. infer_costs = id
|
||||||
-- Or also, if any of -B/-V/-X/--value are active.
|
-- with -B/-V/-X/--value ("because of #551, and because of print -V valuing only one posting when there's an implicit txn price.")
|
||||||
-- Because of #551, and because of print -V valuing only one
|
|
||||||
-- posting when there's an implicit txn price.
|
|
||||||
-- So -B/-V/-X/--value implies -x. Is this ok ?
|
|
||||||
| has (value . _Just) opts = id
|
| has (value . _Just) opts = id
|
||||||
-- By default, use the original as-written-in-the-journal txn.
|
-- Otherwise, keep the transaction's amounts close to how they were written in the journal.
|
||||||
| otherwise = originalTransaction
|
| otherwise = transactionWithMostlyOriginalPostings
|
||||||
|
|
||||||
-- Replace this transaction's postings with the original postings if any, but keep the
|
-- | Replace this transaction's postings with the original postings if any, but keep the
|
||||||
-- current possibly rewritten account names, and the inferred values of any auto postings
|
-- current possibly rewritten account names, and the inferred values of any auto postings.
|
||||||
originalTransaction t = t { tpostings = map originalPostingPreservingAccount $ tpostings t }
|
-- This is mainly for showing transactions with the amounts in their original journal format.
|
||||||
|
transactionWithMostlyOriginalPostings :: Transaction -> Transaction
|
||||||
|
transactionWithMostlyOriginalPostings = transactionMapPostings postingMostlyOriginal
|
||||||
|
|
||||||
-- Get the original posting if any, but keep the current possibly rewritten account name, and
|
-- Get the original posting if any, but keep the current (possibly rewritten) account name,
|
||||||
-- the inferred values of any auto postings
|
-- and the amounts of any auto postings.
|
||||||
originalPostingPreservingAccount p = orig
|
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
|
||||||
|
|||||||
@ -67,7 +67,7 @@ printOrDiff opts
|
|||||||
|
|
||||||
diffOutput :: Journal -> Journal -> IO ()
|
diffOutput :: Journal -> Journal -> IO ()
|
||||||
diffOutput j j' = do
|
diffOutput j j' = do
|
||||||
let changed = [(originalTransaction t, originalTransaction t') | (t, t') <- zip (jtxns j) (jtxns j'), t /= t']
|
let changed = [(transactionWithMostlyOriginalPostings t, transactionWithMostlyOriginalPostings t') | (t, t') <- zip (jtxns j) (jtxns j'), t /= t']
|
||||||
T.putStr $ renderPatch $ map (uncurry $ diffTxn j) changed
|
T.putStr $ renderPatch $ map (uncurry $ diffTxn j) changed
|
||||||
|
|
||||||
type Chunk = (SourcePos, [DiffLine Text])
|
type Chunk = (SourcePos, [DiffLine Text])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user