mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-10 05:39:31 +03:00
;lib: transaction valuation helpers
This commit is contained in:
parent
de0a6b1e62
commit
905149df86
@ -30,6 +30,9 @@ module Hledger.Data.Transaction (
|
||||
isTransactionBalanced,
|
||||
balanceTransaction,
|
||||
balanceTransactionHelper,
|
||||
transactionTransformPostings,
|
||||
transactionApplyValuation,
|
||||
transactionToCost,
|
||||
-- nonzerobalanceerror,
|
||||
-- * date operations
|
||||
transactionDate2,
|
||||
@ -67,6 +70,7 @@ import Hledger.Data.Types
|
||||
import Hledger.Data.Dates
|
||||
import Hledger.Data.Posting
|
||||
import Hledger.Data.Amount
|
||||
import Hledger.Data.Valuation
|
||||
|
||||
sourceFilePath :: GenericSourcePos -> FilePath
|
||||
sourceFilePath = \case
|
||||
@ -553,6 +557,22 @@ txnUntieKnot t@Transaction{tpostings=ps} = t{tpostings=map (\p -> p{ptransaction
|
||||
postingSetTransaction :: Transaction -> Posting -> Posting
|
||||
postingSetTransaction t p = p{ptransaction=Just t}
|
||||
|
||||
-- | Apply a transform function to this transaction's amounts.
|
||||
transactionTransformPostings :: (Posting -> Posting) -> Transaction -> Transaction
|
||||
transactionTransformPostings f t@Transaction{tpostings=ps} = t{tpostings=map f ps}
|
||||
|
||||
-- | Apply a specified valuation to this transaction's amounts, using
|
||||
-- the provided price oracle, commodity styles, reference dates, and
|
||||
-- whether this is for a multiperiod report or not. See
|
||||
-- amountApplyValuation.
|
||||
transactionApplyValuation :: PriceOracle -> M.Map CommoditySymbol AmountStyle -> Day -> Maybe Day -> Day -> Bool -> Transaction -> ValuationType -> Transaction
|
||||
transactionApplyValuation priceoracle styles periodlast mreportlast today ismultiperiod t v =
|
||||
transactionTransformPostings (\p -> postingApplyValuation priceoracle styles periodlast mreportlast today ismultiperiod p v) t
|
||||
|
||||
-- | Convert this transaction's amounts to cost, and apply the appropriate amount styles.
|
||||
transactionToCost :: M.Map CommoditySymbol AmountStyle -> Transaction -> Transaction
|
||||
transactionToCost styles t@Transaction{tpostings=ps} = t{tpostings=map (postingToCost styles) ps}
|
||||
|
||||
-- tests
|
||||
|
||||
tests_Transaction =
|
||||
|
@ -38,6 +38,7 @@ module Hledger.Reports.ReportOptions (
|
||||
reportPeriodLastDay,
|
||||
reportPeriodOrJournalLastDay,
|
||||
valuationTypeIsCost,
|
||||
valuationTypeIsDefaultValue,
|
||||
|
||||
tests_ReportOptions
|
||||
)
|
||||
@ -372,6 +373,12 @@ valuationTypeIsCost ropts =
|
||||
Just (AtCost _) -> True
|
||||
_ -> False
|
||||
|
||||
valuationTypeIsDefaultValue :: ReportOpts -> Bool
|
||||
valuationTypeIsDefaultValue ropts =
|
||||
case value_ ropts of
|
||||
Just (AtDefault _) -> True
|
||||
_ -> False
|
||||
|
||||
type DisplayExp = String
|
||||
|
||||
maybedisplayopt :: Day -> RawOpts -> Maybe DisplayExp
|
||||
|
Loading…
Reference in New Issue
Block a user