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.
This commit is contained in:
Simon Michael 2023-05-27 08:34:11 -10:00
parent d2cefedffb
commit d19d866446

View File

@ -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