ignore virtual transactions when auto-balancing
This commit is contained in:
parent
9acf11de4d
commit
405f71c389
@ -23,8 +23,9 @@ showDescription s = printf "%-20s" (elideRight 20 s)
|
|||||||
isEntryBalanced :: Entry -> Bool
|
isEntryBalanced :: Entry -> Bool
|
||||||
isEntryBalanced (Entry {etransactions=ts}) = isZeroAmount sum && numcommodities==1
|
isEntryBalanced (Entry {etransactions=ts}) = isZeroAmount sum && numcommodities==1
|
||||||
where
|
where
|
||||||
sum = sumLedgerTransactions ts
|
realts = filter isReal ts
|
||||||
numcommodities = length $ nub $ map (symbol . commodity . tamount) ts
|
sum = sumLedgerTransactions realts
|
||||||
|
numcommodities = length $ nub $ map (symbol . commodity . tamount) realts
|
||||||
|
|
||||||
-- | Fill in a missing balance in this entry, if there is one,
|
-- | Fill in a missing balance in this entry, if there is one,
|
||||||
-- or raise an error if there is more than one.
|
-- or raise an error if there is more than one.
|
||||||
|
|||||||
@ -21,18 +21,27 @@ showRawTransaction t = (showaccountname $ taccount t) ++ " " ++ (showamount $ ta
|
|||||||
showaccountname = printf "%-22s" . elideAccountName 22
|
showaccountname = printf "%-22s" . elideAccountName 22
|
||||||
showamount = printf "%12s" . showAmountOrZero
|
showamount = printf "%12s" . showAmountOrZero
|
||||||
|
|
||||||
-- | Fill in the missing balance in an entry's transactions. There can be
|
-- | Fill in the missing balance in an entry's transactions. Excluding
|
||||||
-- at most one missing balance, otherwise we'll return Nothing.
|
-- virtual transactions, there should be at most one missing balance,
|
||||||
|
-- otherwise return Nothing.
|
||||||
autofillTransactions :: [RawTransaction] -> Maybe [RawTransaction]
|
autofillTransactions :: [RawTransaction] -> Maybe [RawTransaction]
|
||||||
autofillTransactions ts =
|
autofillTransactions ts =
|
||||||
case (length blanks) of
|
case (length missingamounts) of
|
||||||
0 -> Just ts
|
0 -> Just ts
|
||||||
1 -> Just $ map balance ts
|
1 -> Just $ map balance ts
|
||||||
otherwise -> Nothing
|
otherwise -> Nothing
|
||||||
where
|
where
|
||||||
(normals, blanks) = partition isnormal ts
|
(reals, _) = partition isReal ts
|
||||||
isnormal t = (symbol $ commodity $ tamount t) /= "AUTO"
|
(realamounts, missingamounts) = partition hasAmount reals
|
||||||
balance t = if isnormal t then t else t{tamount = -(sumLedgerTransactions normals)}
|
balance t = if (isReal t) && (not $ hasAmount t)
|
||||||
|
then t{tamount = -(sumLedgerTransactions realamounts)}
|
||||||
|
else t
|
||||||
|
|
||||||
|
isReal :: RawTransaction -> Bool
|
||||||
|
isReal t = rttype t == RegularTransaction
|
||||||
|
|
||||||
|
hasAmount :: RawTransaction -> Bool
|
||||||
|
hasAmount = ("AUTO" /=) . symbol . commodity . tamount
|
||||||
|
|
||||||
sumLedgerTransactions :: [RawTransaction] -> Amount
|
sumLedgerTransactions :: [RawTransaction] -> Amount
|
||||||
sumLedgerTransactions = sumAmounts . map tamount
|
sumLedgerTransactions = sumAmounts . map tamount
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user