diff --git a/src/accounting/report/reports/trial_balance.py b/src/accounting/report/reports/trial_balance.py index a5507d4..b0dbfd8 100644 --- a/src/accounting/report/reports/trial_balance.py +++ b/src/accounting/report/reports/trial_balance.py @@ -20,7 +20,7 @@ from decimal import Decimal import sqlalchemy as sa -from flask import url_for, Response, render_template +from flask import Response, render_template from accounting import db from accounting.locale import gettext @@ -29,7 +29,7 @@ from accounting.report.period import Period from .utils.base_page_params import BasePageParams from .utils.base_report import BaseReport from .utils.csv_export import BaseCSVRow, csv_download, period_spec -from .utils.get_url import get_ledger_url +from .utils.get_url import get_ledger_url, get_trial_balance_url from .utils.option_link import OptionLink from .utils.period_choosers import TrialBalancePeriodChooser from .utils.report_chooser import ReportChooser @@ -149,14 +149,8 @@ class PageParams(BasePageParams): :return: The currency options. """ - def get_url(currency: Currency): - if self.period.is_default: - return url_for("accounting.report.trial-balance-default", - currency=currency) - return url_for("accounting.report.trial-balance", - currency=currency, period=self.period) - - return self._get_currency_options(get_url, self.currency) + return self._get_currency_options( + lambda x: get_trial_balance_url(x, self.period), self.currency) class TrialBalance(BaseReport): diff --git a/src/accounting/report/reports/utils/get_url.py b/src/accounting/report/reports/utils/get_url.py index cf959e9..86d0a48 100644 --- a/src/accounting/report/reports/utils/get_url.py +++ b/src/accounting/report/reports/utils/get_url.py @@ -58,6 +58,20 @@ def get_income_expenses_url(currency: Currency, account: IncomeExpensesAccount, period=period) +def get_trial_balance_url(currency: Currency, period: Period) -> str: + """Returns the URL of a trial balance. + + :param currency: The currency. + :param period: The period. + :return: The URL of the trial balance. + """ + if period.is_default: + return url_for("accounting.report.trial-balance-default", + currency=currency) + return url_for("accounting.report.trial-balance", + currency=currency, period=period) + + def get_income_statement_url(currency: Currency, period: Period) -> str: """Returns the URL of an income statement. diff --git a/src/accounting/report/reports/utils/period_choosers.py b/src/accounting/report/reports/utils/period_choosers.py index 0f9545f..ae22d49 100644 --- a/src/accounting/report/reports/utils/period_choosers.py +++ b/src/accounting/report/reports/utils/period_choosers.py @@ -31,7 +31,7 @@ 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_income_statement_url + get_trial_balance_url, get_income_statement_url class PeriodChooser(ABC): @@ -165,11 +165,7 @@ class TrialBalancePeriodChooser(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.trial-balance-default", - currency=self.currency) - return url_for("accounting.report.trial-balance", - currency=self.currency, period=period) + return get_trial_balance_url(self.currency, period) class IncomeStatementPeriodChooser(PeriodChooser): diff --git a/src/accounting/report/reports/utils/report_chooser.py b/src/accounting/report/reports/utils/report_chooser.py index e45a914..2a62ca9 100644 --- a/src/accounting/report/reports/utils/report_chooser.py +++ b/src/accounting/report/reports/utils/report_chooser.py @@ -33,7 +33,7 @@ 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_income_statement_url + get_trial_balance_url, get_income_statement_url from .option_link import OptionLink from .report_type import ReportType @@ -130,12 +130,9 @@ class ReportChooser: :return: The trial balance. """ - url: str = url_for("accounting.report.trial-balance-default", - currency=self.__currency) \ - if self.__period.is_default \ - else url_for("accounting.report.trial-balance", - currency=self.__currency, period=self.__period) - return OptionLink(gettext("Trial Balance"), url, + return OptionLink(gettext("Trial Balance"), + get_trial_balance_url(self.__currency, + self.__period), self.__active_report == ReportType.TRIAL_BALANCE, fa_icon="fa-solid fa-scale-unbalanced")