Revert "add: suggest only one commodity at a time as default amount #383"

Overcommitted.

This reverts commit 92b97e7bd3.
This commit is contained in:
Simon Michael 2016-08-06 19:59:18 -07:00
parent 92b97e7bd3
commit 009fe6d09f
6 changed files with 19 additions and 76 deletions

View File

@ -48,20 +48,13 @@ nullacct = Account
, asubs = []
, anumpostings = 0
, aebalance = nullmixedamt
, aestartbalance = nullmixedamt
, aeperiodchange = nullmixedamt
, aeendbalance = nullmixedamt
, aibalance = nullmixedamt
, aistartbalance = nullmixedamt
, aiperiodchange = nullmixedamt
, aiendbalance = nullmixedamt
, aboring = False
}
-- | Derive 1. an account tree and 2. their total changes from a list of postings.
-- | Derive 1. an account tree and 2. their balances from a list of postings.
-- (ledger's core feature). The accounts are returned in a list, but
-- also reference each other as a tree structure; the first account is
-- the root of the tree.
-- retain their tree structure; the first one is the root of the tree.
accountsFromPostings :: [Posting] -> [Account]
accountsFromPostings ps =
let

View File

@ -18,11 +18,9 @@ import Text.Printf
import Hledger.Data.Types
import Hledger.Data.Account
import Hledger.Data.Dates
import Hledger.Data.Journal
import Hledger.Data.Posting
import Hledger.Query
import Hledger.Utils.Debug
instance Show Ledger where
@ -41,33 +39,16 @@ nullledger = Ledger {
-- | Filter a journal's transactions with the given query, then derive
-- a ledger containing the chart of accounts and balances. If the
-- query includes a depth limit, that will affect the ledger's
-- query includes a depth limit, that will affect the this ledger's
-- journal but not the ledger's account tree.
ledgerFromJournal :: Query -> Journal -> Ledger
ledgerFromJournal q j = nullledger{ljournal=depthclippedperiodj, laccounts=as}
ledgerFromJournal q j = nullledger{ljournal=j'', laccounts=as}
where
symq = filterQuery queryIsSym q
depthq = filterQuery queryIsDepth q
periodq = filterQuery (not . queryIsDepth) q
-- get account totals before and during report period
datelessq = filterQuery (not . queryIsDateOrDate2) periodq
dateqcons = Date -- if date2_ opts then Date2 else Date -- import cycle, don't bother supporting date2
reportspan = queryDateSpan False {-(date2_ opts)-} q -- date span specified by -b/-e/-p options and query args
mstartdate = dbg1 "mstartdate" $ spanStart reportspan
menddate = dbg1 "menddate" $ spanEnd reportspan
precedingq = dbg1 "precedingq" $
case mstartdate of
Just _ -> And [datelessq, dateqcons $ DateSpan Nothing mstartdate]
Nothing -> None
-- remove amount parts which the query's sym: terms would exclude
precedingj = filterJournalAmounts symq $ filterJournalPostings precedingq j
periodj = filterJournalAmounts symq $ filterJournalPostings periodq j
precedingas = accountsFromPostings $ journalPostings precedingj
as = accountsFromPostings $ journalPostings periodj
depthclippedperiodj = filterJournalPostings depthq periodj
-- j' = journalSelectingAmountFromOpts opts j
(q',depthq) = (filterQuery (not . queryIsDepth) q, filterQuery queryIsDepth q)
j' = filterJournalAmounts (filterQuery queryIsSym q) $ -- remove amount parts which the query's sym: terms would exclude
filterJournalPostings q' j
as = accountsFromPostings $ journalPostings j'
j'' = filterJournalPostings depthq j'
-- | List a ledger's account names.
ledgerAccountNames :: Ledger -> [AccountName]

View File

@ -281,8 +281,8 @@ instance NFData MarketPrice
--
data Journal = Journal {
-- parsing-related data
jparsedefaultyear :: Maybe Year -- ^ the current default year, specified by the most recent Y directive (or current date)
,jparsedefaultcommodity :: Maybe (CommoditySymbol,AmountStyle) -- ^ the current default commodity and its format, specified by the most recent D directive
jparsedefaultyear :: (Maybe Year) -- ^ the current default year, specified by the most recent Y directive (or current date)
,jparsedefaultcommodity :: (Maybe (CommoditySymbol,AmountStyle)) -- ^ the current default commodity and its format, specified by the most recent D directive
,jparseparentaccounts :: [AccountName] -- ^ the current stack of parent account names, specified by apply account directives
,jparsealiases :: [AccountAlias] -- ^ the current account name aliases in effect, specified by alias directives (& options ?)
,jparsetransactioncount :: Integer -- ^ the current count of transactions parsed so far (only journal format txns, currently)
@ -329,23 +329,15 @@ data Reader = Reader {
instance Show Reader where show r = rFormat r ++ " reader"
-- | An account, with name, links to parent/subaccounts
-- which let you walk up or down the account tree, and
-- and start/end balances and balance change amount relative to
-- some report period.
-- | An account, with name, balances and links to parent/subaccounts
-- which let you walk up or down the account tree.
data Account = Account {
aname :: AccountName, -- ^ this account's full name
aebalance :: MixedAmount, -- ^ this account's balance, excluding subaccounts
aestartbalance :: MixedAmount, -- ^ this account's balance at start of report period, excluding subaccounts
aeperiodchange :: MixedAmount, -- ^ the change in this account's balance during the report period, excluding subaccounts
aeendbalance :: MixedAmount, -- ^ this account's balance at end of report period, excluding subaccounts
asubs :: [Account], -- ^ sub-accounts
anumpostings :: Int, -- ^ number of postings to this account
-- derived from the above :
aibalance :: MixedAmount, -- ^ this account's balance, including subaccounts
aistartbalance :: MixedAmount, -- ^ this account's balance at start of report period, excluding subaccounts
aiperiodchange :: MixedAmount, -- ^ the change in this account's balance during the report period, excluding subaccounts
aiendbalance :: MixedAmount, -- ^ this account's balance at end of report period, excluding subaccounts
aparent :: Maybe Account, -- ^ parent account
aboring :: Bool -- ^ used in the accounts report to label elidable parents
} deriving (Typeable, Data, Generic)

View File

@ -22,7 +22,7 @@ import Hledger.Reports.ReportOptions
import Hledger.Reports.TransactionsReports
-- | Get the historical inclusive balance of a particular account over time,
-- | Get the historical running inclusive balance of a particular account,
-- from earliest to latest posting date.
accountBalanceHistory :: ReportOpts -> Journal -> Account -> [(Day, MixedAmount)]
accountBalanceHistory ropts j a = [(getdate t, bal) | (t,_,_,_,_,bal) <- items]

View File

@ -5,13 +5,6 @@ Balance report, used by the balance command.
-}
module Hledger.Reports.BalanceReport (
BalanceReport,
BalanceReportItem,
@ -38,12 +31,6 @@ import Hledger.Utils
import Hledger.Reports.ReportOptions
-- | A simple single-column balance report. It has:
--
-- 1. a list of rows, each containing a renderable account name and a corresponding amount
@ -154,8 +141,8 @@ mixedAmountValue :: Journal -> Day -> MixedAmount -> MixedAmount
mixedAmountValue j d (Mixed as) = Mixed $ map (amountValue j d) as
-- | Find the market value of this amount on the given date, in it's
-- default valuation commodity, based on recorded market prices.
-- If no default valuation commodity can be found, the amount is left
-- default valuation commodity, based on historical prices. If no
-- default valuation commodity can be found, the amount is left
-- unchanged.
amountValue :: Journal -> Day -> Amount -> Amount
amountValue j d a =
@ -168,7 +155,7 @@ amountValue j d a =
-- | Find the market value, if known, of one unit of this commodity on
-- the given date, in the commodity in which it has most recently been
-- market-priced (ie the commodity mentioned in the most recent
-- applicable market price directive before this date).
-- applicable historical price directive before this date).
commodityValue :: Journal -> Day -> CommoditySymbol -> Maybe Amount
commodityValue j d c
| null applicableprices = Nothing
@ -176,13 +163,6 @@ commodityValue j d c
where
applicableprices = [p | p <- sort $ jmarketprices j, mpcommodity p == c, mpdate p <= d]
tests_balanceReport =
let
(opts,journal) `gives` r = do

View File

@ -260,7 +260,6 @@ accountWizard EntryState{..} = do
| otherwise = Just t
dbg1 = id -- strace
amountAndCommentWizard :: EntryState -> Wizard Haskeline (Amount, Text)
amountAndCommentWizard EntryState{..} = do
let pnum = length esPostings + 1
(mhistoricalp,followedhistoricalsofar) =
@ -271,7 +270,7 @@ amountAndCommentWizard EntryState{..} = do
def = case (esArgs, mhistoricalp, followedhistoricalsofar) of
(d:_,_,_) -> d
(_,Just hp,True) -> showamt $ pamount hp
_ | pnum > 1 && not (isZeroMixedAmount balancingamt) -> showamt balancingamtfirstcommodity
_ | pnum > 1 && not (isZeroMixedAmount balancingamt) -> showamt balancingamt
_ -> ""
retryMsg "A valid hledger amount is required. Eg: 1, $2, 3 EUR, \"4 red apples\"." $
parser parseAmountAndComment $
@ -294,9 +293,7 @@ amountAndCommentWizard EntryState{..} = do
-- eof
return (a,c)
balancingamt = negate $ sum $ map pamount realps where realps = filter isReal esPostings
balancingamtfirstcommodity = Mixed $ take 1 $ amounts balancingamt
showamt =
showMixedAmountWithPrecision
showamt = showMixedAmountWithPrecision
-- what should this be ?
-- 1 maxprecision (show all decimal places or none) ?
-- 2 maxprecisionwithpoint (show all decimal places or .0 - avoids some but not all confusion with thousands separators) ?