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

@ -28,6 +28,7 @@ from accounting.models import Currency, Account, Transaction, JournalEntry
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 TrialBalancePeriodChooser
@ -200,23 +201,11 @@ class TrialBalance(BaseReport):
accounts: dict[int, Account] \
= {x.id: x for x in Account.query
.filter(Account.id.in_([x.id for x in balances])).all()}
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 = [ReportAccount(account=accounts[x.id],
amount=x.balance,
url=get_url(accounts[x.id]))
url=get_ledger_url(self.__currency,
accounts[x.id],
self.__period))
for x in balances]
self.__total = Total(
sum([x.debit for x in self.__accounts if x.debit is not None]),