mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 07:09:28 +03:00
preserve transaction order regardless of where the blank one is
This commit is contained in:
parent
11c96dd042
commit
573fac2755
@ -21,13 +21,14 @@ elideRight width s =
|
||||
|
||||
autofillTransactions :: [LedgerTransaction] -> [LedgerTransaction]
|
||||
autofillTransactions ts =
|
||||
let (ns, as) = partition isNormal ts
|
||||
where isNormal t = (symbol $ currency $ tamount t) /= "AUTO" in
|
||||
case (length as) of
|
||||
0 -> ns
|
||||
1 -> ns ++ [balanceTransaction $ head as]
|
||||
where balanceTransaction t = t{tamount = -(sumLedgerTransactions ns)}
|
||||
case (length blanks) of
|
||||
0 -> ts
|
||||
1 -> map balance ts
|
||||
otherwise -> error "too many blank transactions in this entry"
|
||||
where
|
||||
(normals, blanks) = partition isnormal ts
|
||||
balance t = if isnormal t then t else t{tamount = -(sumLedgerTransactions normals)}
|
||||
isnormal t = (symbol $ currency $ tamount t) /= "AUTO"
|
||||
|
||||
sumLedgerTransactions :: [LedgerTransaction] -> Amount
|
||||
sumLedgerTransactions = sum . map tamount
|
||||
|
Loading…
Reference in New Issue
Block a user