Added the get_ledger_url utility to replace the common codes to retrieve the URL of a ledger.

This commit is contained in:
2023-03-09 11:18:36 +08:00
parent 6d1e705e4b
commit 74b695c089
7 changed files with 65 additions and 76 deletions

View File

@ -29,6 +29,7 @@ from accounting.models import Currency, BaseAccount, Account, Transaction, \
from accounting.report.period import Period
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.option_link import OptionLink
from .utils.base_page_params import BasePageParams
from .utils.period_choosers import BalanceSheetPeriodChooser
@ -144,24 +145,12 @@ class AccountCollector:
Account.base_code == "3353")).all()
account_by_id: dict[int, Account] \
= {x.id: x for x in self.__all_accounts}
def get_url(account: Account) -> str:
"""Returns the ledger URL of an account.
:param account: The account.
:return: The ledger URL of the account.
"""
if self.__period.is_default:
return url_for("accounting.report.ledger-default",
currency=self.__currency, account=account)
return url_for("accounting.report.ledger",
currency=self.__currency, account=account,
period=self.__period)
self.accounts: list[ReportAccount] \
= [ReportAccount(account=account_by_id[x.id],
amount=x.balance,
url=get_url(account_by_id[x.id]))
url=get_ledger_url(self.__currency,
account_by_id[x.id],
self.__period))
for x in account_balances]
self.__add_accumulated()
self.__add_current_period()