diff --git a/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs b/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs index 03763edd0..b212a6658 100644 --- a/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs +++ b/hledger-lib/Hledger/Reports/AccountTransactionsReport.hs @@ -27,7 +27,6 @@ import Data.List (mapAccumR, nub, partition, sortBy) import Data.List.Extra (nubSort) import Data.Maybe (catMaybes) import Data.Ord (Down(..), comparing) -import Data.Text (Text) import qualified Data.Text as T import Data.Time.Calendar (Day) @@ -80,7 +79,7 @@ type AccountTransactionsReportItem = Transaction -- the transaction, unmodified ,Transaction -- the transaction, as seen from the current account ,Bool -- is this a split (more than one posting to other accounts) ? - ,Text -- a display string describing the other account(s), if any + ,[AccountName] -- the other account(s), if any ,MixedAmount -- the amount posted to the current account(s) (or total amount posted) ,MixedAmount -- the register's running total or the current account(s)'s historical balance, after this transaction ) @@ -188,14 +187,14 @@ accountTransactionsReportItem reportq thisacctq signfn accttypefn bal (d, t) -- 201407: I've lost my grip on this, let's just hope for the best -- 201606: we now calculate change and balance from filtered postings, check this still works well for all callers XXX | null reportps = (bal, Nothing) -- no matched postings in this transaction, skip it - | otherwise = (bal', Just (t, tacct{tdate=d}, numotheraccts > 1, otheracctstr, amt, bal')) + | otherwise = (bal', Just (t, tacct{tdate=d}, numotheraccts > 1, otheraccts, amt, bal')) where tacct@Transaction{tpostings=reportps} = filterTransactionPostingsExtra accttypefn reportq t -- TODO needs to consider --date2, #1731 (thisacctps, otheracctps) = partition (matchesPosting thisacctq) reportps numotheraccts = length $ nub $ map paccount otheracctps - otheracctstr | thisacctq == None = summarisePostingAccounts reportps -- no current account ? summarise all matched postings - | numotheraccts == 0 = summarisePostingAccounts thisacctps -- only postings to current account ? summarise those - | otherwise = summarisePostingAccounts otheracctps -- summarise matched postings to other account(s) + otheraccts | thisacctq == None = summarisePostingAccounts reportps -- no current account ? summarise all matched postings + | numotheraccts == 0 = summarisePostingAccounts thisacctps -- only postings to current account ? summarise those + | otherwise = summarisePostingAccounts otheracctps -- summarise matched postings to other account(s) -- 202302: Impact of t on thisacct - normally the sum of thisacctps, -- but if they are null it probably means reportq is an account filter -- and we should sum otheracctps instead. @@ -236,9 +235,8 @@ transactionRegisterDate wd reportq thisacctq t -- | Generate a simplified summary of some postings' accounts. -- To reduce noise, if there are both real and virtual postings, show only the real ones. -summarisePostingAccounts :: [Posting] -> Text -summarisePostingAccounts ps = - T.intercalate ", " . map accountSummarisedName . nub $ map paccount displayps +summarisePostingAccounts :: [Posting] -> [AccountName] +summarisePostingAccounts ps = map paccount displayps where realps = filter isReal ps displayps | null realps = ps diff --git a/hledger-ui/Hledger/UI/UIScreens.hs b/hledger-ui/Hledger/UI/UIScreens.hs index f59edea4e..bbc3d38f2 100644 --- a/hledger-ui/Hledger/UI/UIScreens.hs +++ b/hledger-ui/Hledger/UI/UIScreens.hs @@ -42,6 +42,7 @@ where import Brick.Widgets.List (listMoveTo, listSelectedElement, list) import Data.List import Data.Maybe +import qualified Data.Text as T import Data.Time.Calendar (Day, diffDays) import Safe import qualified Data.Vector as V @@ -280,11 +281,11 @@ rsUpdate uopts d j rss@RSS{_rssAccount, _rssForceInclusive, _rssList=oldlist} = -- pre-render the list items, helps calculate column widths displayitems = map displayitem items' where - displayitem (t, _, _issplit, otheracctsstr, change, bal) = + displayitem (t, _, _issplit, otheraccts, change, bal) = RegisterScreenItem{rsItemDate = showDate $ transactionRegisterDate wd (_rsQuery rspec') thisacctq t ,rsItemStatus = tstatus t ,rsItemDescription = tdescription t - ,rsItemOtherAccounts = otheracctsstr + ,rsItemOtherAccounts = T.intercalate ", " . map accountSummarisedName $ nub otheraccts -- _ -> "" -- should do this if accounts field width < 30 ,rsItemChangeAmount = showamt change ,rsItemBalanceAmount = showamt bal diff --git a/hledger/Hledger/Cli/Commands/Aregister.hs b/hledger/Hledger/Cli/Commands/Aregister.hs index 24c9a4b4d..a63badf63 100644 --- a/hledger/Hledger/Cli/Commands/Aregister.hs +++ b/hledger/Hledger/Cli/Commands/Aregister.hs @@ -20,7 +20,7 @@ module Hledger.Cli.Commands.Aregister ( ) where import Data.Default (def) -import Data.List (find) +import Data.List (find, nub) import Data.Maybe (fromMaybe) import Data.Text (Text) import Data.Foldable (for_) @@ -157,12 +157,12 @@ accountTransactionsReportItemAsRecord :: [Spr.Cell Spr.NumLines Text] accountTransactionsReportItemAsRecord fmt internals wd reportq thisacctq - (t@Transaction{tindex,tcode,tdescription}, _, _issplit, otheracctsstr, change, balance) + (t@Transaction{tindex,tcode,tdescription}, _, _issplit, otheraccts, change, balance) = (optional internals [Spr.integerCell tindex]) ++ date : (optional internals [cell tcode]) ++ [cell tdescription, - cell otheracctsstr, + cell $ T.intercalate ", " $ nub otheraccts, amountCell change, amountCell balance] where @@ -244,11 +244,11 @@ accountTransactionsReportItemAsText :: CliOpts -> Query -> Query -> Int -> Int accountTransactionsReportItemAsText copts@CliOpts{reportspec_=ReportSpec{_rsReportOpts=ropts}} reportq thisacctq preferredamtwidth preferredbalwidth - ((t@Transaction{tdescription}, _, _issplit, otheracctsstr, _, _), amt, bal) = + ((t@Transaction{tdescription}, _, _issplit, otheraccts, _, _), amt, bal) = -- Transaction -- the transaction, unmodified -- Transaction -- the transaction, as seen from the current account -- Bool -- is this a split (more than one posting to other accounts) ? - -- String -- a display string describing the other account(s), if any + -- [AccountName] -- the other account(s), if any -- MixedAmount -- the amount posted to the current account(s) (or total amount posted) -- MixedAmount -- the register's running total or the current account(s)'s historical balance, after this transaction table <> TB.singleton '\n' @@ -287,9 +287,7 @@ accountTransactionsReportItemAsText (descwidth, acctwidth) = (w, remaining - 2 - w) where w = fromMaybe ((remaining - 2) `div` 2) mdescwidth - -- gather content - accts = -- T.unpack $ elideAccountName acctwidth $ T.pack - otheracctsstr + accts = T.intercalate ", " . map accountSummarisedName $ nub otheraccts -- tests