From d19d8664461e880a2497966567899e7964cad2c3 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 27 May 2023 08:34:11 -1000 Subject: [PATCH] fix: use costs when balancing a txn with a balance assignment (fix #2039) Transaction balancing is supposed to balance costs, but these were being stripped when calculating balance assignments, causing us to wrongly reject this transaction when the last amount is left implicit, unlike Ledger: 2023-01-01 Assets AAA -1.1 @@ CCC 2 Assets BBB -1.2 @@ CCC 3 Expenses:Fees CCC 0.2 Assets = CCC 4.9 I'm not sure why costs were being stripped. I seem to have added it in 2019 (to Journal.balanceNoAssignmentTransactionB in 3b47b58ae), but this bug seems to be present even before that. --- hledger-lib/Hledger/Data/Balancing.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hledger-lib/Hledger/Data/Balancing.hs b/hledger-lib/Hledger/Data/Balancing.hs index ce05a2cb5..4a33a5511 100644 --- a/hledger-lib/Hledger/Data/Balancing.hs +++ b/hledger-lib/Hledger/Data/Balancing.hs @@ -33,7 +33,6 @@ import Control.Monad.Reader as R (ReaderT, reader, runReaderT, ask, asks) import Control.Monad.ST (ST, runST) import Control.Monad.Trans.Class (lift) import Data.Array.ST (STArray, getElems, newListArray, writeArray) -import Data.Bifunctor (second) import Data.Foldable (asum) import Data.Function ((&)) import Data.Functor ((<&>)) @@ -514,7 +513,7 @@ balanceTransactionAndCheckAssertionsB (Right t@Transaction{tpostings=ps}) = do ps' <- ps & zip [1..] -- attach original positions & sortOn (postingDate.snd) -- sort by date - & mapM (addOrAssignAmountAndCheckAssertionB . second postingStripPrices) -- infer amount, check assertion on each one + & mapM (addOrAssignAmountAndCheckAssertionB) -- infer amount, check assertion on each one <&> sortOn fst -- restore original order <&> map snd -- discard positions