Added the get_journal_url utility to replace the common codes to retrieve the URL of an income statement.

This commit is contained in:
依瑪貓 2023-03-09 11:34:29 +08:00
parent 740e1cfac1
commit a65dccac92
3 changed files with 18 additions and 11 deletions

View File

@ -24,6 +24,18 @@ from accounting.report.income_expense_account import IncomeExpensesAccount
from accounting.report.period import Period 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) \ def get_ledger_url(currency: Currency, account: Account, period: Period) \
-> str: -> str:
"""Returns the URL of a ledger. """Returns the URL of a ledger.

View File

@ -30,8 +30,8 @@ from accounting.report.income_expense_account import IncomeExpensesAccount
from accounting.report.period import YearPeriod, Period, ThisMonth, \ from accounting.report.period import YearPeriod, Period, ThisMonth, \
LastMonth, SinceLastMonth, ThisYear, LastYear, Today, Yesterday, \ LastMonth, SinceLastMonth, ThisYear, LastYear, Today, Yesterday, \
TemplatePeriod TemplatePeriod
from .get_url import get_ledger_url, get_income_expenses_url, \ from .get_url import get_journal_url, get_ledger_url, \
get_trial_balance_url, get_income_statement_url get_income_expenses_url, get_trial_balance_url, get_income_statement_url
class PeriodChooser(ABC): class PeriodChooser(ABC):
@ -114,9 +114,7 @@ class JournalPeriodChooser(PeriodChooser):
super().__init__(None if first is None else first.date) super().__init__(None if first is None else first.date)
def _url_for(self, period: Period) -> str: def _url_for(self, period: Period) -> str:
if period.is_default: return get_journal_url(period)
return url_for("accounting.report.journal-default")
return url_for("accounting.report.journal", period=period)
class LedgerPeriodChooser(PeriodChooser): class LedgerPeriodChooser(PeriodChooser):

View File

@ -32,8 +32,8 @@ from accounting.models import Currency, Account
from accounting.report.income_expense_account import IncomeExpensesAccount from accounting.report.income_expense_account import IncomeExpensesAccount
from accounting.report.period import Period from accounting.report.period import Period
from accounting.template_globals import default_currency_code from accounting.template_globals import default_currency_code
from .get_url import get_ledger_url, get_income_expenses_url, \ from .get_url import get_journal_url, get_ledger_url, \
get_trial_balance_url, get_income_statement_url get_income_expenses_url, get_trial_balance_url, get_income_statement_url
from .option_link import OptionLink from .option_link import OptionLink
from .report_type import ReportType from .report_type import ReportType
@ -88,10 +88,7 @@ class ReportChooser:
:return: The journal. :return: The journal.
""" """
url: str = url_for("accounting.report.journal-default") \ return OptionLink(gettext("Journal"), get_journal_url(self.__period),
if self.__period.is_default \
else url_for("accounting.report.journal", period=self.__period)
return OptionLink(gettext("Journal"), url,
self.__active_report == ReportType.JOURNAL, self.__active_report == ReportType.JOURNAL,
fa_icon="fa-solid fa-book") fa_icon="fa-solid fa-book")