ENH check accounts in multiallocations

This commit is contained in:
Nathan Dwarshuis 2023-05-29 17:14:01 -04:00
parent b586f958cb
commit c3ab976407
1 changed files with 8 additions and 2 deletions

View File

@ -40,7 +40,7 @@ insertBudget
, bgtInterval , bgtInterval
} = } =
whenHash CTBudget b () $ \key -> do whenHash CTBudget b () $ \key -> do
intAllos <- combineError3 pre_ tax_ post_ (,,) (intAllos, _) <- combineError intAlloRes acntRes (,)
let res1 = mapErrors (insertIncome key bgtLabel intAllos bgtInterval) bgtIncomes let res1 = mapErrors (insertIncome key bgtLabel intAllos bgtInterval) bgtIncomes
let res2 = expandTransfers key bgtLabel bgtInterval bgtTransfers let res2 = expandTransfers key bgtLabel bgtInterval bgtTransfers
txs <- combineError (concat <$> res1) res2 (++) txs <- combineError (concat <$> res1) res2 (++)
@ -48,10 +48,16 @@ insertBudget
shadow <- liftExcept $ addShadowTransfers m bgtShadowTransfers txs shadow <- liftExcept $ addShadowTransfers m bgtShadowTransfers txs
void $ mapErrors insertBudgetTx $ balanceTransfers $ txs ++ shadow void $ mapErrors insertBudgetTx $ balanceTransfers $ txs ++ shadow
where where
acntRes = mapErrors isNotIncomeAcnt alloAcnts
intAlloRes = combineError3 pre_ tax_ post_ (,,)
pre_ = sortAllos bgtPretax pre_ = sortAllos bgtPretax
tax_ = sortAllos bgtTax tax_ = sortAllos bgtTax
post_ = sortAllos bgtPosttax post_ = sortAllos bgtPosttax
sortAllos = liftExcept . combineErrors . fmap sortAllo sortAllos = liftExcept . mapErrors sortAllo
alloAcnts =
(alloAcnt <$> bgtPretax)
++ (alloAcnt <$> bgtTax)
++ (alloAcnt <$> bgtPosttax)
balanceTransfers :: [UnbalancedTransfer] -> [BalancedTransfer] balanceTransfers :: [UnbalancedTransfer] -> [BalancedTransfer]
balanceTransfers = snd . L.mapAccumR go M.empty . reverse . L.sortOn ftWhen balanceTransfers = snd . L.mapAccumR go M.empty . reverse . L.sortOn ftWhen