From 1e766e481e0f685fb70aa162873af5f70fe4ae1c Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Wed, 25 Aug 2021 00:01:12 +1000 Subject: [PATCH] cln: Flatten dependency tree by removing dependencies of Hledger.Reports on Hledger.Read. This is done by using equivalent functions/types defined elsewhere instead. --- hledger-lib/Hledger/Reports/BalanceReport.hs | 67 +++++++++---------- hledger-lib/Hledger/Reports/BudgetReport.hs | 3 +- .../Hledger/Reports/MultiBalanceReport.hs | 7 +- 3 files changed, 37 insertions(+), 40 deletions(-) diff --git a/hledger-lib/Hledger/Reports/BalanceReport.hs b/hledger-lib/Hledger/Reports/BalanceReport.hs index 9b3de3e43..e7386c8b0 100644 --- a/hledger-lib/Hledger/Reports/BalanceReport.hs +++ b/hledger-lib/Hledger/Reports/BalanceReport.hs @@ -22,7 +22,6 @@ where import Data.Time.Calendar import Hledger.Data -import Hledger.Read (mamountp') import Hledger.Query import Hledger.Utils import Hledger.Reports.MultiBalanceReport (multiBalanceReport) @@ -119,46 +118,46 @@ tests_BalanceReport = testGroup "BalanceReport" [ ,testCase "no args, sample journal" $ (defreportspec, samplejournal) `gives` ([ - ("assets:bank:checking","assets:bank:checking",0, mamountp' "$1.00") - ,("assets:bank:saving","assets:bank:saving",0, mamountp' "$1.00") - ,("assets:cash","assets:cash",0, mamountp' "$-2.00") - ,("expenses:food","expenses:food",0, mamountp' "$1.00") - ,("expenses:supplies","expenses:supplies",0, mamountp' "$1.00") - ,("income:gifts","income:gifts",0, mamountp' "$-1.00") - ,("income:salary","income:salary",0, mamountp' "$-1.00") + ("assets:bank:checking","assets:bank:checking",0, mixedAmount (usd 1)) + ,("assets:bank:saving","assets:bank:saving",0, mixedAmount (usd 1)) + ,("assets:cash","assets:cash",0, mixedAmount (usd (-2))) + ,("expenses:food","expenses:food",0, mixedAmount (usd 1)) + ,("expenses:supplies","expenses:supplies",0, mixedAmount (usd 1)) + ,("income:gifts","income:gifts",0, mixedAmount (usd (-1))) + ,("income:salary","income:salary",0, mixedAmount (usd (-1))) ], mixedAmount (usd 0)) ,testCase "with --tree" $ (defreportspec{_rsReportOpts=defreportopts{accountlistmode_=ALTree}}, samplejournal) `gives` ([ - ("assets","assets",0, mamountp' "$0.00") - ,("assets:bank","bank",1, mamountp' "$2.00") - ,("assets:bank:checking","checking",2, mamountp' "$1.00") - ,("assets:bank:saving","saving",2, mamountp' "$1.00") - ,("assets:cash","cash",1, mamountp' "$-2.00") - ,("expenses","expenses",0, mamountp' "$2.00") - ,("expenses:food","food",1, mamountp' "$1.00") - ,("expenses:supplies","supplies",1, mamountp' "$1.00") - ,("income","income",0, mamountp' "$-2.00") - ,("income:gifts","gifts",1, mamountp' "$-1.00") - ,("income:salary","salary",1, mamountp' "$-1.00") + ("assets","assets",0, mixedAmount (usd 0)) + ,("assets:bank","bank",1, mixedAmount (usd 2)) + ,("assets:bank:checking","checking",2, mixedAmount (usd 1)) + ,("assets:bank:saving","saving",2, mixedAmount (usd 1)) + ,("assets:cash","cash",1, mixedAmount (usd (-2))) + ,("expenses","expenses",0, mixedAmount (usd 2)) + ,("expenses:food","food",1, mixedAmount (usd 1)) + ,("expenses:supplies","supplies",1, mixedAmount (usd 1)) + ,("income","income",0, mixedAmount (usd (-2))) + ,("income:gifts","gifts",1, mixedAmount (usd (-1))) + ,("income:salary","salary",1, mixedAmount (usd (-1))) ], mixedAmount (usd 0)) ,testCase "with --depth=N" $ (defreportspec{_rsReportOpts=defreportopts{depth_=Just 1}}, samplejournal) `gives` ([ - ("expenses", "expenses", 0, mamountp' "$2.00") - ,("income", "income", 0, mamountp' "$-2.00") + ("expenses", "expenses", 0, mixedAmount (usd 2)) + ,("income", "income", 0, mixedAmount (usd (-2))) ], mixedAmount (usd 0)) ,testCase "with depth:N" $ (defreportspec{_rsQuery=Depth 1}, samplejournal) `gives` ([ - ("expenses", "expenses", 0, mamountp' "$2.00") - ,("income", "income", 0, mamountp' "$-2.00") + ("expenses", "expenses", 0, mixedAmount (usd 2)) + ,("income", "income", 0, mixedAmount (usd (-2))) ], mixedAmount (usd 0)) @@ -169,27 +168,27 @@ tests_BalanceReport = testGroup "BalanceReport" [ ,testCase "with date2:" $ (defreportspec{_rsQuery=Date2 $ DateSpan (Just $ fromGregorian 2009 01 01) (Just $ fromGregorian 2010 01 01)}, samplejournal2) `gives` ([ - ("assets:bank:checking","assets:bank:checking",0,mamountp' "$1.00") - ,("income:salary","income:salary",0,mamountp' "$-1.00") + ("assets:bank:checking","assets:bank:checking",0,mixedAmount (usd 1)) + ,("income:salary","income:salary",0,mixedAmount (usd (-1))) ], mixedAmount (usd 0)) ,testCase "with desc:" $ (defreportspec{_rsQuery=Desc $ toRegexCI' "income"}, samplejournal) `gives` ([ - ("assets:bank:checking","assets:bank:checking",0,mamountp' "$1.00") - ,("income:salary","income:salary",0, mamountp' "$-1.00") + ("assets:bank:checking","assets:bank:checking",0,mixedAmount (usd 1)) + ,("income:salary","income:salary",0, mixedAmount (usd (-1))) ], mixedAmount (usd 0)) ,testCase "with not:desc:" $ (defreportspec{_rsQuery=Not . Desc $ toRegexCI' "income"}, samplejournal) `gives` ([ - ("assets:bank:saving","assets:bank:saving",0, mamountp' "$1.00") - ,("assets:cash","assets:cash",0, mamountp' "$-2.00") - ,("expenses:food","expenses:food",0, mamountp' "$1.00") - ,("expenses:supplies","expenses:supplies",0, mamountp' "$1.00") - ,("income:gifts","income:gifts",0, mamountp' "$-1.00") + ("assets:bank:saving","assets:bank:saving",0, mixedAmount (usd 1)) + ,("assets:cash","assets:cash",0, mixedAmount (usd (-2))) + ,("expenses:food","expenses:food",0, mixedAmount (usd 1)) + ,("expenses:supplies","expenses:supplies",0, mixedAmount (usd 1)) + ,("income:gifts","income:gifts",0, mixedAmount (usd (-1))) ], mixedAmount (usd 0)) @@ -197,8 +196,8 @@ tests_BalanceReport = testGroup "BalanceReport" [ (defreportspec{_rsReportOpts=defreportopts{period_= PeriodBetween (fromGregorian 2008 1 1) (fromGregorian 2008 1 2)}}, samplejournal) `gives` ( [ - ("assets:bank:checking","assets:bank:checking",0, mamountp' "$1.00") - ,("income:salary","income:salary",0, mamountp' "$-1.00") + ("assets:bank:checking","assets:bank:checking",0, mixedAmount (usd 1)) + ,("income:salary","income:salary",0, mixedAmount (usd (-1))) ], mixedAmount (usd 0)) diff --git a/hledger-lib/Hledger/Reports/BudgetReport.hs b/hledger-lib/Hledger/Reports/BudgetReport.hs index 94153f20d..8d2ce0ea5 100644 --- a/hledger-lib/Hledger/Reports/BudgetReport.hs +++ b/hledger-lib/Hledger/Reports/BudgetReport.hs @@ -42,7 +42,6 @@ import Text.Tabular.AsciiWide as Tab import Hledger.Data import Hledger.Utils -import Hledger.Read.CsvReader (CSV) import Hledger.Reports.ReportOptions import Hledger.Reports.ReportTypes import Hledger.Reports.MultiBalanceReport @@ -401,7 +400,7 @@ budgetReportAsTable -- XXX generalise this with multiBalanceReportAsCsv ? -- | Render a budget report as CSV. Like multiBalanceReportAsCsv, -- but includes alternating actual and budget amount columns. -budgetReportAsCsv :: ReportOpts -> BudgetReport -> CSV +budgetReportAsCsv :: ReportOpts -> BudgetReport -> [[Text]] budgetReportAsCsv ReportOpts{..} (PeriodicReport colspans items tr) diff --git a/hledger-lib/Hledger/Reports/MultiBalanceReport.hs b/hledger-lib/Hledger/Reports/MultiBalanceReport.hs index 7880d6bc9..16765facd 100644 --- a/hledger-lib/Hledger/Reports/MultiBalanceReport.hs +++ b/hledger-lib/Hledger/Reports/MultiBalanceReport.hs @@ -59,7 +59,6 @@ import Hledger.Data import Hledger.Query import Hledger.Utils hiding (dbg3,dbg4,dbg5) import qualified Hledger.Utils -import Hledger.Read (mamountp') import Hledger.Reports.ReportOptions import Hledger.Reports.ReportTypes @@ -606,10 +605,10 @@ tests_MultiBalanceReport = testGroup "MultiBalanceReport" [ ,testCase "with -H on a populated period" $ (defreportspec{_rsReportOpts=defreportopts{period_= PeriodBetween (fromGregorian 2008 1 1) (fromGregorian 2008 1 2), balanceaccum_=Historical}}, samplejournal) `gives` ( - [ PeriodicReportRow (flatDisplayName "assets:bank:checking") [mamountp' "$1.00"] (mamountp' "$1.00") (mixedAmount amt0{aquantity=1}) - , PeriodicReportRow (flatDisplayName "income:salary") [mamountp' "$-1.00"] (mamountp' "$-1.00") (mixedAmount amt0{aquantity=(-1)}) + [ PeriodicReportRow (flatDisplayName "assets:bank:checking") [mixedAmount $ usd 1] (mixedAmount $ usd 1) (mixedAmount amt0{aquantity=1}) + , PeriodicReportRow (flatDisplayName "income:salary") [mixedAmount $ usd (-1)] (mixedAmount $ usd (-1)) (mixedAmount amt0{aquantity=(-1)}) ], - mamountp' "$0.00") + mixedAmount $ usd 0) -- ,testCase "a valid history on an empty period" $ -- (defreportopts{period_= PeriodBetween (fromGregorian 2008 1 2) (fromGregorian 2008 1 3), balanceaccum_=Historical}, samplejournal) `gives`