mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-26 20:02:27 +03:00
Fix for auto-balancing transactions which have negative amount in the first posting
This commit is contained in:
parent
2daa56dcb3
commit
2c01541de1
@ -189,9 +189,10 @@ balanceTransaction canonicalcommoditymap t@Transaction{tpostings=ps}
|
||||
where
|
||||
conversionprice c | c == unpricedcommodity
|
||||
-- assign a balancing price. Use @@ for more exact output when possible.
|
||||
-- invariant: prices should always be positive. Enforced with "abs"
|
||||
= if length ramountsinunpricedcommodity == 1
|
||||
then Just $ TotalPrice $ Mixed [setAmountPrecision maxprecision $ negate $ targetcommodityamount]
|
||||
else Just $ UnitPrice $ Mixed [setAmountPrecision maxprecision $ negate $ targetcommodityamount `divideAmount` (quantity unpricedamount)]
|
||||
then Just $ TotalPrice $ Mixed [setAmountPrecision maxprecision $ abs $ targetcommodityamount]
|
||||
else Just $ UnitPrice $ Mixed [setAmountPrecision maxprecision $ abs $ targetcommodityamount `divideAmount` (quantity unpricedamount)]
|
||||
| otherwise = Nothing
|
||||
where
|
||||
unpricedcommodity = head $ filter (`elem` (map commodity rsumamounts)) rcommoditiesinorder
|
||||
@ -214,8 +215,8 @@ balanceTransaction canonicalcommoditymap t@Transaction{tpostings=ps}
|
||||
where
|
||||
conversionprice c | c == unpricedcommodity
|
||||
= if length bvamountsinunpricedcommodity == 1
|
||||
then Just $ TotalPrice $ Mixed [setAmountPrecision maxprecision $ negate $ targetcommodityamount]
|
||||
else Just $ UnitPrice $ Mixed [setAmountPrecision maxprecision $ negate $ targetcommodityamount `divideAmount` (quantity unpricedamount)]
|
||||
then Just $ TotalPrice $ Mixed [setAmountPrecision maxprecision $ abs $ targetcommodityamount]
|
||||
else Just $ UnitPrice $ Mixed [setAmountPrecision maxprecision $ abs $ targetcommodityamount `divideAmount` (quantity unpricedamount)]
|
||||
| otherwise = Nothing
|
||||
where
|
||||
unpricedcommodity = head $ filter (`elem` (map commodity bvsumamounts)) bvcommoditiesinorder
|
||||
|
@ -71,7 +71,8 @@ data Commodity = Commodity {
|
||||
|
||||
-- | An amount's price may be written as \@ unit price or \@\@ total price.
|
||||
-- Note although Price has a MixedAmount, it should hold only
|
||||
-- single-commodity amounts, cf costOfAmount.
|
||||
-- single-commodity amounts, cf costOfAmount. Moreover, price should always
|
||||
-- be positive, though it is currently not enforced.
|
||||
data Price = UnitPrice MixedAmount | TotalPrice MixedAmount
|
||||
deriving (Eq,Ord)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user