From a65dccac9225cdb740059c12322fb27a47a17e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Thu, 9 Mar 2023 11:34:29 +0800 Subject: [PATCH] Added the get_journal_url utility to replace the common codes to retrieve the URL of an income statement. --- src/accounting/report/reports/utils/get_url.py | 12 ++++++++++++ .../report/reports/utils/period_choosers.py | 8 +++----- .../report/reports/utils/report_chooser.py | 9 +++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/accounting/report/reports/utils/get_url.py b/src/accounting/report/reports/utils/get_url.py index 86d0a48..e802ce5 100644 --- a/src/accounting/report/reports/utils/get_url.py +++ b/src/accounting/report/reports/utils/get_url.py @@ -24,6 +24,18 @@ from accounting.report.income_expense_account import IncomeExpensesAccount from accounting.report.period import Period +def get_journal_url(period: Period) \ + -> str: + """Returns the URL of a journal. + + :param period: The period. + :return: The URL of the journal. + """ + if period.is_default: + return url_for("accounting.report.journal-default") + return url_for("accounting.report.journal", period=period) + + def get_ledger_url(currency: Currency, account: Account, period: Period) \ -> str: """Returns the URL of a ledger. diff --git a/src/accounting/report/reports/utils/period_choosers.py b/src/accounting/report/reports/utils/period_choosers.py index ae22d49..e1ef8bd 100644 --- a/src/accounting/report/reports/utils/period_choosers.py +++ b/src/accounting/report/reports/utils/period_choosers.py @@ -30,8 +30,8 @@ from accounting.report.income_expense_account import IncomeExpensesAccount from accounting.report.period import YearPeriod, Period, ThisMonth, \ LastMonth, SinceLastMonth, ThisYear, LastYear, Today, Yesterday, \ TemplatePeriod -from .get_url import get_ledger_url, get_income_expenses_url, \ - get_trial_balance_url, get_income_statement_url +from .get_url import get_journal_url, get_ledger_url, \ + get_income_expenses_url, get_trial_balance_url, get_income_statement_url class PeriodChooser(ABC): @@ -114,9 +114,7 @@ class JournalPeriodChooser(PeriodChooser): super().__init__(None if first is None else first.date) def _url_for(self, period: Period) -> str: - if period.is_default: - return url_for("accounting.report.journal-default") - return url_for("accounting.report.journal", period=period) + return get_journal_url(period) class LedgerPeriodChooser(PeriodChooser): diff --git a/src/accounting/report/reports/utils/report_chooser.py b/src/accounting/report/reports/utils/report_chooser.py index 2a62ca9..8164ce8 100644 --- a/src/accounting/report/reports/utils/report_chooser.py +++ b/src/accounting/report/reports/utils/report_chooser.py @@ -32,8 +32,8 @@ from accounting.models import Currency, Account from accounting.report.income_expense_account import IncomeExpensesAccount from accounting.report.period import Period from accounting.template_globals import default_currency_code -from .get_url import get_ledger_url, get_income_expenses_url, \ - get_trial_balance_url, get_income_statement_url +from .get_url import get_journal_url, get_ledger_url, \ + get_income_expenses_url, get_trial_balance_url, get_income_statement_url from .option_link import OptionLink from .report_type import ReportType @@ -88,10 +88,7 @@ class ReportChooser: :return: The journal. """ - url: str = url_for("accounting.report.journal-default") \ - if self.__period.is_default \ - else url_for("accounting.report.journal", period=self.__period) - return OptionLink(gettext("Journal"), url, + return OptionLink(gettext("Journal"), get_journal_url(self.__period), self.__active_report == ReportType.JOURNAL, fa_icon="fa-solid fa-book")