mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-26 20:02:27 +03:00
print, web: always show both dates, ignoring --effective (#42)
Ledger shows only the effective date with --effective, but not vice versa. print is supposed to be information-preserving so this seems better. This also fixes the web entries view.
This commit is contained in:
parent
9a0a0be01c
commit
35f3a4fa00
10
MANUAL.md
10
MANUAL.md
@ -1203,9 +1203,13 @@ entries, and the following c++ ledger options and commands:
|
||||
- hledger's output follows the decimal point character, digit grouping,
|
||||
and digit group separator character used in the journal.
|
||||
|
||||
- hledger print shows amounts for all postings, and shows unit
|
||||
prices for amounts which have them. (This currently means that
|
||||
it does not print multi-commodity transactions in valid journal format.)
|
||||
- hledger print shows amounts for all postings, and shows unit prices for
|
||||
amounts which have them. (This means that it does not currently print
|
||||
multi-commodity transactions in valid journal format.)
|
||||
|
||||
- hledger print ignores the --effective flag, always showing both dates.
|
||||
ledger print shows only the effective date with --effective, but not
|
||||
vice versa.
|
||||
|
||||
- hledger's default commodity directive (D) sets the commodity for
|
||||
subsequent commodityless amounts, and contributes to that commodity's
|
||||
|
1
NOTES
1
NOTES
@ -550,6 +550,7 @@ using be more place holders?
|
||||
*** 33 edit form always displays in non-javascript browsers, like elinks
|
||||
*** 25 hledger in windows console does not print non-ascii characters
|
||||
*** convert: manual needs a rewrite
|
||||
*** web: manual needs update
|
||||
*** parsing: recursive file includes cause a hang
|
||||
echo "!include rec" > rec
|
||||
hledger -f rec print
|
||||
|
@ -216,10 +216,6 @@ matchesTransaction _ _ = False
|
||||
postingEffectiveDate :: Posting -> Maybe Day
|
||||
postingEffectiveDate p = maybe Nothing (Just . transactionEffectiveDate) $ ptransaction p
|
||||
|
||||
transactionEffectiveDate :: Transaction -> Day
|
||||
transactionEffectiveDate t = case teffectivedate t of Just d -> d
|
||||
Nothing -> tdate t
|
||||
|
||||
-- | Does the match expression match this account ?
|
||||
-- A matching in: clause is also considered a match.
|
||||
matchesAccount :: Matcher -> AccountName -> Bool
|
||||
|
@ -10,6 +10,7 @@ module Hledger.Data.Transaction
|
||||
where
|
||||
import Data.List
|
||||
import Data.Maybe
|
||||
import Data.Time.Calendar
|
||||
import Test.HUnit
|
||||
import Text.Printf
|
||||
import qualified Data.Map as Map
|
||||
@ -233,10 +234,18 @@ nonzerobalanceerror t = printf "could not balance this transaction (%s%s%s)" rms
|
||||
| otherwise = "balanced virtual postings are off by " ++ show (costOfMixedAmount bvsum)
|
||||
sep = if not (null rmsg) && not (null bvmsg) then "; " else ""
|
||||
|
||||
-- | Convert the primary date to either the actual or effective date.
|
||||
transactionActualDate :: Transaction -> Day
|
||||
transactionActualDate = tdate
|
||||
|
||||
-- Get a transaction's effective date, defaulting to the actual date.
|
||||
transactionEffectiveDate :: Transaction -> Day
|
||||
transactionEffectiveDate t = fromMaybe (tdate t) $ teffectivedate t
|
||||
|
||||
-- | Once we no longer need both, set the main transaction date to either
|
||||
-- the actual or effective date. A bit hacky.
|
||||
journalTransactionWithDate :: WhichDate -> Transaction -> Transaction
|
||||
journalTransactionWithDate ActualDate t = t
|
||||
journalTransactionWithDate EffectiveDate t = txnTieKnot t{tdate=fromMaybe (tdate t) (teffectivedate t)}
|
||||
journalTransactionWithDate EffectiveDate t = txnTieKnot t{tdate=transactionEffectiveDate t}
|
||||
|
||||
-- | Ensure a transaction's postings refer back to it.
|
||||
txnTieKnot :: Transaction -> Transaction
|
||||
|
@ -146,10 +146,14 @@ clearedValueFromOpts ReportOpts{..} | cleared_ = Just True
|
||||
| uncleared_ = Just False
|
||||
| otherwise = Nothing
|
||||
|
||||
-- | Detect which date we will report on, based on --effective.
|
||||
-- | Report which date we will report on based on --effective.
|
||||
whichDateFromOpts :: ReportOpts -> WhichDate
|
||||
whichDateFromOpts ReportOpts{..} = if effective_ then EffectiveDate else ActualDate
|
||||
|
||||
-- | Select a Transaction date accessor based on --effective.
|
||||
transactionDateFn :: ReportOpts -> (Transaction -> Day)
|
||||
transactionDateFn ReportOpts{..} = if effective_ then transactionEffectiveDate else transactionActualDate
|
||||
|
||||
-- | Convert this journal's transactions' primary date to either the
|
||||
-- actual or effective date, as per options.
|
||||
journalSelectingDateFromOpts :: ReportOpts -> Journal -> Journal
|
||||
@ -197,9 +201,10 @@ type EntriesReportItem = Transaction
|
||||
|
||||
-- | Select transactions for an entries report.
|
||||
entriesReport :: ReportOpts -> FilterSpec -> Journal -> EntriesReport
|
||||
entriesReport opts fspec j = sortBy (comparing tdate) $ jtxns $ filterJournalTransactions fspec j'
|
||||
entriesReport opts fspec j = sortBy (comparing f) $ jtxns $ filterJournalTransactions fspec j'
|
||||
where
|
||||
j' = journalSelectingDateFromOpts opts $ journalSelectingAmountFromOpts opts j
|
||||
f = transactionDateFn opts
|
||||
j' = journalSelectingAmountFromOpts opts j
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
|
@ -1,11 +0,0 @@
|
||||
bin/hledger -f - print --effective
|
||||
<<<
|
||||
2009/1/1=2010/1/1 x
|
||||
a 1
|
||||
b
|
||||
>>>
|
||||
2010/01/01 x
|
||||
a 1
|
||||
b -1
|
||||
|
||||
>>>=0
|
@ -1,16 +1,17 @@
|
||||
#
|
||||
# print shows both dates. The second's year defaults to the first's.
|
||||
bin/hledger -f - print --effective
|
||||
<<<
|
||||
2009/1/1=1/2 x
|
||||
a 1
|
||||
b
|
||||
>>>
|
||||
2009/01/02 x
|
||||
2009/01/01=2009/01/02 x
|
||||
a 1
|
||||
b -1
|
||||
|
||||
>>>2
|
||||
>>>= 0
|
||||
|
||||
# Effective date of 29 Feb on leap year should be valid
|
||||
bin/hledger -f - print --effective
|
||||
<<<
|
||||
@ -18,7 +19,7 @@ bin/hledger -f - print --effective
|
||||
a 1
|
||||
b
|
||||
>>>
|
||||
2000/02/29 x
|
||||
2001/02/27=2000/02/29 x
|
||||
a 1
|
||||
b -1
|
||||
|
Loading…
Reference in New Issue
Block a user